mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
python 0860.柠檬水找零 去除无用变量
python 0860.柠檬水找零 去除无用变量:在本题中,20的数量是无用的,因为不需要用来找零,可以不用维护这个变量。
This commit is contained in:
@ -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
|
||||||
|
Reference in New Issue
Block a user