python 0860.柠檬水找零 去除无用变量

python 0860.柠檬水找零 去除无用变量:在本题中,20的数量是无用的,因为不需要用来找零,可以不用维护这个变量。
This commit is contained in:
SianXiaoCHN
2022-04-03 23:42:04 -05:00
parent 9b9a37b92c
commit 69a9316beb

View File

@ -157,7 +157,7 @@ class Solution {
```python ```python
class Solution: class Solution:
def lemonadeChange(self, bills: List[int]) -> bool: def lemonadeChange(self, bills: List[int]) -> bool:
five, ten, twenty = 0, 0, 0 five, ten = 0, 0
for bill in bills: for bill in bills:
if bill == 5: if bill == 5:
five += 1 five += 1
@ -169,10 +169,8 @@ class Solution:
if ten > 0 and five > 0: if ten > 0 and five > 0:
ten -= 1 ten -= 1
five -= 1 five -= 1
twenty += 1
elif five > 2: elif five > 2:
five -= 3 five -= 3
twenty += 1
else: else:
return False return False
return True return True