Skip to content

Latest commit

 

History

History
31 lines (29 loc) · 759 Bytes

860.md

File metadata and controls

31 lines (29 loc) · 759 Bytes

860. Lemonade Change

Solution 1 (time O(n), space O(1))

class Solution(object):
    def lemonadeChange(self, bills):
        """
        :type bills: List[int]
        :rtype: bool
        """
        five, ten = 0, 0
        for bill in bills:
            if bill == 5:
                five += 1
            elif bill == 10:
                if five >= 1:
                    five -= 1
                    ten += 1
                else:
                    return False
            elif bill == 20:
                if five >= 1 and ten >= 1:
                    five -= 1
                    ten -= 1
                elif five >= 3:
                    five -= 3
                else:
                    return False
        return True