-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLemonade-Change.py
More file actions
31 lines (31 loc) · 1017 Bytes
/
Copy pathLemonade-Change.py
File metadata and controls
31 lines (31 loc) · 1017 Bytes
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
class Solution:
def lemonadeChange(self, bills: List[int]) -> bool:
denom = {
5: 0,
10: 0,
20: 0
}
for i in range(len(bills)):
denom[bills[i]] += 1
if bills[i] > 5:
bal = bills[i] - 5
if bal % 5 == 0 and bal % 10 != 0:
if denom[5] > 0:
denom[5] -= 1
bal -= 5
if bal == 0:
continue
if bal % 10 == 0 and bal % 20 != 0:
if denom[10] > 0:
denom[10] -= 1
bal -= 10
if bal == 0:
continue
if denom[5] > 1:
denom[5] -= 2
bal -= 10
if bal == 0:
continue
if bal > 0:
return False
return True