-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path860.cpp
More file actions
31 lines (31 loc) · 862 Bytes
/
860.cpp
File metadata and controls
31 lines (31 loc) · 862 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
class Solution {
public:
bool lemonadeChange(vector<int>& bills) {
unordered_map<int,int> change;
change[5] = 0;change[10] = 0;change[20] = 0;
for(auto x: bills){
int diff = x-5;
change[x]++;
if(diff!=0){
if(diff==5){
if(change[5]!=0)
change[5]--;
else
return false;
}
else{
if(change[10]>0 && change[5]>0){
change[10]--;
change[5]--;
}
else if(change[5]>=3){
change[5]-=3;
}
else
return false;
}
}
}
return true;
}
};