HTMLify

LeetCode - Lemonade Change - Python
Views: 9 | Author: abh
class Solution:
    def lemonadeChange(self, bills: List[int]) -> bool:
        galla = []
        for bill in bills:
            if bill == 5:
                galla.append(5)
            if bill == 10:
                if 5 not in galla:
                    return False
                galla.remove(5)
                galla.append(10)
            if bill == 20:
                if not ((5 in galla and 10 in galla) or (galla.count(5) >= 3)):
                    return False
                if 10 in galla:
                    galla.remove(10)
                else:
                    galla.remove(5)
                    galla.remove(5)
                galla.remove(5)
                galla.append(20)
        return True

Comments