-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path860.py
34 lines (24 loc) · 924 Bytes
/
860.py
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
# leetcode 860 柠檬水找零
class Solution:
def lemonadeChange(self, bills: List[int]) -> bool:
# 这道题目还是用贪心来做
chargedict = dict()
for i in bills:
# 一共有三种情况
if i == 5:
chargedict[i] = chargedict.get(i, 0) + 1
if i == 10:
if chargedict.get(5, 0) <= 0:
return False
else:
chargedict[i] = chargedict.get(i, 0) + 1
chargedict[5] -= 1
if i == 20:
if chargedict.get(5, 0) > 0 and chargedict.get(10, 0) > 0:
chargedict[5] -= 1
chargedict[10] -= 1
elif chargedict.get(5, 0) >= 3 and chargedict.get(10, 0) == 0:
chargedict[5] -= 3
else:
return False
return True