-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path柠檬水找零
33 lines (33 loc) · 824 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
33
class Solution {
public:
bool lemonadeChange(vector<int>& bills) {
unordered_map<int,int> map;
for(int i=0;i<bills.size();i++){
if(bills[i]==5){
map[5]++;
}
else if(bills[i]==10){
if(map[5]>0){
map[5]--;
map[10]++;
}
else{
return false;
}
}
else if(bills[i]==20){
if(map[5]>=1&&map[10]>=1){
map[5]--;
map[10]--;
}
else if(map[5]>=3){
map[5]=map[5]-3;
}
else{
return false;
}
}
}
return true;
}
};