-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlemonadeChange.py
More file actions
37 lines (30 loc) · 1.09 KB
/
lemonadeChange.py
File metadata and controls
37 lines (30 loc) · 1.09 KB
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
35
36
37
"""
At a lemonade stand, each lemonade costs $5.
Customers are standing in a queue to buy from you, and order one at a time (in the order specified by bills).
Each customer will only buy one lemonade and pay with either a $5, $10, or $20 bill.
You must provide the correct change to each customer, so that the net transaction is that the customer pays $5.
Note that you don't have any change in hand at first.
Return true if and only if you can provide every customer with correct change.
"""
class Solution:
def lemonadeChange(self, bills: list[int]) -> bool:
fives = 0
tens = 0
for i in bills:
if i == 5:
fives += 1
if i == 10:
if fives < 1:
return False
else:
fives -= 1
tens += 1
if i == 20:
if tens >= 1 and fives >= 1:
tens -= 1
fives -= 1
elif fives >= 3:
fives -= 3
else:
return False
return True