LeetCode860. 柠檬水找零
- 题目链接
- 代码
题目链接
https://leetcode.cn/problems/lemonade-change/
代码
class Solution:
def lemonadeChange(self, bills: List[int]) -> bool:
five = 0
ten = 0
twenty = 0
for i in range(len(bills)):
if bills[i] == 5:
five += 1
if bills[i] == 10:
if five > 0:
five -= 1
ten += 1
else:
return False
if bills[i] == 20:
if ten > 0 and five > 0:
ten -= 1
five -= 1
twenty += 1
elif five > 2:
five -= 3
twenty += 1
else:
return False
return True