Skip to content

Commit 63e65b1

Browse files
committed
2020-08-19
1 parent 4ec6971 commit 63e65b1

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

0860.柠檬水找零/0860-柠檬水找零.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@ def lemonadeChange(self, bills):
44
:type bills: List[int]
55
:rtype: bool
66
"""
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-
five -= 1
16-
ten -= 1
17-
elif num == 20 and five >= 3:
18-
five -= 3
7+
dic = {5:0, 10:0}
8+
9+
for bill in bills:
10+
if bill == 5:
11+
dic[5] += 1
12+
elif bill == 10:
13+
if dic[5] < 1:
14+
return False
15+
dic[5] -= 1
16+
dic[10] += 1
1917
else:
20-
return False
21-
return True
18+
if dic[10] and dic[5]:
19+
dic[10] -= 1
20+
dic[5] -= 1
21+
elif dic[5] >= 3:
22+
dic[5] -= 3
23+
else:
24+
return False
25+
return True

0 commit comments

Comments
 (0)