mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-10 04:06:51 +08:00
Update 0860.柠檬水找零.md
Added python version code
This commit is contained in:
@ -156,7 +156,30 @@ class Solution {
|
|||||||
```
|
```
|
||||||
|
|
||||||
Python:
|
Python:
|
||||||
|
```python
|
||||||
|
class Solution:
|
||||||
|
def lemonadeChange(self, bills: List[int]) -> bool:
|
||||||
|
five, ten, twenty = 0, 0, 0
|
||||||
|
for bill in bills:
|
||||||
|
if bill == 5:
|
||||||
|
five += 1
|
||||||
|
elif bill == 10:
|
||||||
|
if five < 1: return False
|
||||||
|
five -= 1
|
||||||
|
ten += 1
|
||||||
|
else:
|
||||||
|
if ten > 0 and five > 0:
|
||||||
|
ten -= 1
|
||||||
|
five -= 1
|
||||||
|
twenty += 1
|
||||||
|
elif five > 2:
|
||||||
|
five -= 3
|
||||||
|
twenty += 1
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
Go:
|
Go:
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user