forked from fredfeng0326/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlet860.py
30 lines (27 loc) · 771 Bytes
/
let860.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
# 860. Lemonade Change
class Solution:
def lemonadeChange(self, bills):
"""
:type bills: List[int]
:rtype: bool
"""
wallet = {5:0,10:0}
for bill in bills:
# 5
if bill == 5:
wallet[5] += 1
elif bill == 10:
if wallet[5] > 0:
wallet[10] += 1
wallet[5] -= 1
else:
return False
elif bill == 20:
if wallet[10] > 0 and wallet[5] > 0:
wallet[10] -= 1
wallet[5] -=1
elif wallet[5] >= 3:
wallet[5] -= 3
else:
return False
return True