-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL860.py
More file actions
29 lines (24 loc) · 777 Bytes
/
L860.py
File metadata and controls
29 lines (24 loc) · 777 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
# 860. 柠檬水找零
from typing import List
class Solution:
def lemonadeChange(self, bills: List[int]) -> bool:
five = 0
ten = 0
for bill in bills:
if bill == 5:
five += 1
elif bill == 10:
if five == 0: return False
five -= 1
ten += 1
else:
if not (ten * 10 + five * 5 >= 15 and five != 0): return False
ten -= 1
five -= 1
return True
if __name__ == '__main__':
s = Solution()
ans = s.lemonadeChange([5, 5, 5, 10, 20])
ans = s.lemonadeChange([5, 5, 10, 20, 5, 5, 5, 5, 5, 5, 5, 5, 5, 10, 5, 5, 20, 5, 20, 5])
# ans = s.lemonadeChange([5, 5, 10, 10, 20])
print(ans)