860. Lemonade Change
All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : August 15, 2024
Last updated : August 15, 2024
Related Topics : Array, Greedy
Acceptance Rate : 58.32 %
class Solution:
def lemonadeChange(self, bills: List[int]) -> bool:
register = [0] * 2
for bill in bills :
match bill :
case 5 :
register[0] += 1
case 10 :
if not register[0] :
return False
register[0] -= 1
register[1] += 1
case 20 :
if register[1] and register[0] :
register[0] -= 1
register[1] -= 1
elif register[0] >= 3 :
register[0] -= 3
else :
return False
return True