We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4ec6971 commit 63e65b1Copy full SHA for 63e65b1
0860.柠檬水找零/0860-柠檬水找零.py
@@ -4,18 +4,22 @@ def lemonadeChange(self, bills):
4
:type bills: List[int]
5
:rtype: bool
6
"""
7
- five = ten = 0
8
- for num in bills:
9
- if num == 5:
10
- five += 1
11
- elif num == 10 and five:
12
- ten += 1
13
- five -= 1
14
- elif num == 20 and five and ten:
15
16
- ten -= 1
17
- elif num == 20 and five >= 3:
18
- five -= 3
+ dic = {5:0, 10:0}
+
+ for bill in bills:
+ if bill == 5:
+ dic[5] += 1
+ elif bill == 10:
+ if dic[5] < 1:
+ return False
+ dic[5] -= 1
+ dic[10] += 1
19
else:
20
- return False
21
- return True
+ if dic[10] and dic[5]:
+ dic[10] -= 1
+ elif dic[5] >= 3:
22
+ dic[5] -= 3
23
+ else:
24
25
+ return True
0 commit comments