Update 0860.柠檬水找零.md

This commit is contained in:
jianghongcheng
2023-06-01 01:37:41 -05:00
committed by GitHub
parent cfb10d2e2a
commit ba3c7ec19b

View File

@ -164,24 +164,39 @@ class Solution {
```python
class Solution:
def lemonadeChange(self, bills: List[int]) -> bool:
five, ten = 0, 0
five = 0
ten = 0
twenty = 0
for bill in bills:
# 情况一收到5美元
if bill == 5:
five += 1
elif bill == 10:
if five < 1: return False
five -= 1
# 情况二收到10美元
if bill == 10:
if five <= 0:
return False
ten += 1
else:
if ten > 0 and five > 0:
ten -= 1
five -= 1
# 情况三收到20美元
if bill == 20:
# 先尝试使用10美元和5美元找零
if five > 0 and ten > 0:
five -= 1
elif five > 2:
ten -= 1
#twenty += 1
# 如果无法使用10美元找零则尝试使用三张5美元找零
elif five >= 3:
five -= 3
#twenty += 1
else:
return False
return True
```
### Go