leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0860.cpp (752B)
0 class Solution {
1 public:
2 bool lemonadeChange(const vector<int> &bills) const {
3 int count[2] = {0, 0};
5 for (const int n : bills) {
6 switch (n) {
7 case 5: count[0]++; break;
8 case 10:
9 if (count[0] == 0) return false;
10 count[0]--;
11 count[1]++;
12 break;
13 case 20:
14 if (count[0] > 0 && count[1] > 0) {
15 count[0]--;
16 count[1]--;
17 break;
18 }
20 if (count[0] >= 3) {
21 count[0] -= 3;
22 break;
23 }
25 return false;
26 }
27 }
29 return true;
30 }
31 };