-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetcode第860题.cpp
More file actions
49 lines (49 loc) · 1.23 KB
/
Leetcode第860题.cpp
File metadata and controls
49 lines (49 loc) · 1.23 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class Solution {
public:
bool lemonadeChange(vector<int>& bills) {
if(bills.size()==1){
return true;
}//就一个顾客,肯定找得开
int charge[3]={0,0,0};
bool res=true;
for(int i=0;i<bills.size();++i)
{
switch(bills[i]){
case 5:
charge[0]++;
break;
case 10:
charge[1]++;
break;
default:
charge[2]++;
}//先收一张零钱
if(bills[i]==5){
continue;
}
else if(bills[i]==10){
if(charge[0]==0){
res=false;
break;
}
else{
charge[0]--;
}
}
else{
if(charge[1]>0&&charge[0]>0){
charge[1]--;
charge[0]--;
}
else if(charge[0]>=3){
charge[0]-=3;
}
else{
res=false;
break;
}
}
}
return res;
}
};