-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path0860.cpp
More file actions
32 lines (28 loc) · 752 Bytes
/
Copy path0860.cpp
File metadata and controls
32 lines (28 loc) · 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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;
}
};