-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy path0860-lemonade-change.py
More file actions
31 lines (27 loc) · 864 Bytes
/
0860-lemonade-change.py
File metadata and controls
31 lines (27 loc) · 864 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
# time complexity: O(n)
# space complexity: O(1)
from typing import List
class Solution:
def lemonadeChange(self, bills: List[int]) -> bool:
fiveBillCount = 0
tenBillCount = 0
for bill in bills:
if bill == 5:
fiveBillCount += 1
elif bill == 10:
if fiveBillCount == 0:
return False
else:
fiveBillCount -= 1
tenBillCount += 1
else:
if fiveBillCount > 0 and tenBillCount > 0:
fiveBillCount -= 1
tenBillCount -= 1
elif fiveBillCount >= 3:
fiveBillCount -= 3
else:
return False
return True
bills = [5, 5, 10, 10, 20]
print(Solution().lemonadeChange(bills))