-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.py
More file actions
30 lines (28 loc) · 803 Bytes
/
solution.py
File metadata and controls
30 lines (28 loc) · 803 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
class Solution(object):
def lemonadeChange(self, bills):
"""
:type bills: List[int]
:rtype: bool
"""
remains = {
5: 0,
10: 0
}
for bill in bills:
if bill == 5:
remains[5] += 1
elif bill == 10:
if remains[5] > 0:
remains[5] -= 1
remains[10] += 1
else:
return False
elif bill == 20:
if remains[10] > 0 and remains[5] > 0:
remains[5] -= 1
remains[10] -= 1
elif remains[5] >= 3:
remains[5] -= 3
else:
return False
return True