This commit is contained in:
parent
c91899827b
commit
e6c5de02e1
1 changed files with 24 additions and 0 deletions
24
easy/lemonade_change.py
Normal file
24
easy/lemonade_change.py
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
# https://leetcode.com/problems/lemonade-change
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
class Solution:
|
||||||
|
def lemonadeChange(self, bills: List[int]) -> bool:
|
||||||
|
inventory: List[int] = [0, 0]
|
||||||
|
for bill in bills:
|
||||||
|
match bill:
|
||||||
|
case 5:
|
||||||
|
inventory[0] += 1
|
||||||
|
case 10:
|
||||||
|
inventory[0] -= 1
|
||||||
|
inventory[1] += 1
|
||||||
|
if inventory[0] < 0:
|
||||||
|
return False
|
||||||
|
case 20:
|
||||||
|
if inventory[1] == 0:
|
||||||
|
inventory[0] -= 3
|
||||||
|
else:
|
||||||
|
inventory[1] -= 1
|
||||||
|
inventory[0] -= 1
|
||||||
|
if inventory[0] < 0 or inventory[1] < 0:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
Loading…
Add table
Add a link
Reference in a new issue