Skip to content

Latest commit

 

History

History
51 lines (39 loc) · 1.24 KB

_860. Lemonade Change.md

File metadata and controls

51 lines (39 loc) · 1.24 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : August 15, 2024

Last updated : August 15, 2024


Related Topics : Array, Greedy

Acceptance Rate : 58.32 %


Solutions

Python

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