leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE | |
commit | a012edcff84a22149474cc4d9601b03390a60d44 |
parent | d48e9be6397b54369e7ce10048ae9c3952c87500 |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Thu, 15 Aug 2024 18:09:16 +0200 |
Daily Problem
Diffstat:A | Problems/0860.cpp | | | ++++++++++++++++++++++++++++++++ |
M | README.md | | | + |
2 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/Problems/0860.cpp b/Problems/0860.cpp
@@ -0,0 +1,32 @@
class Solution {
public:
bool lemonadeChange(const vector<int> &bills) const {
int count[2] = {0, 0};
for (const int n : bills) {
switch (n) {
case 5: count[0]++; break;
case 10:
if (count[0] == 0) return false;
count[0]--;
count[1]++;
break;
case 20:
if (count[0] > 0 && count[1] > 0) {
count[0]--;
count[1]--;
break;
}
if (count[0] >= 3) {
count[0] -= 3;
break;
}
return false;
}
}
return true;
}
};
diff --git a/README.md b/README.md
@@ -538,6 +538,7 @@ for solving problems.
| 0857 | Hard | [Minimum Cost to Hire K Workers](Problems/0857.cpp) |
| 0858 | Medium | [Mirror Reflection](Problems/0858.cpp) |
| 0859 | Easy | [Buddy Strings](Problems/0859.cpp) |
| 0860 | Easy | [Lemonade Change](Problems/0860.cpp) |
| 0861 | Medium | [Score After Flipping Matrix](Problems/0861.cpp) |
| 0863 | Medium | [All Nodes Distance K in Binary Tree](Problems/0863.cpp) |
| 0864 | Hard | [Shortest Path to Get All Keys](Problems/0864.cpp) |