<jupyter_start><jupyter_text>LeetCode 860. Lemonade Change    At a lemonade stand, each lemonade costs $5.Customers are standing in a queue to buy from you, and order one at a time (in the order specified by bills).Each customer will only buy one lemonade and pay with either a $5, $10, or $20 bill.  You must provide the correct change to each customer, so that the net transaction is that the customer pays $5.    Note that you don't have any change in hand at first.    Return true if and only if you can provide every customer with correct change.    Example 1:    Input: [5,5,5,10,20]    Output: true    Explanation:     From the first 3 customers, we collect three $5 bills in order.From the fourth customer, we collect a $10 bill and give back a $5.From the fifth customer, we give a $10 bill and a $5 bill.    Since all customers got correct change, we output true.        Example 2:    Input: [5,5,10]    Output: true    Example 3:    Input: [10,10]    Output: false    Example 4:    Input: [5,5,10,10,20]    Output: false        Explanation:     From the first two customers in order, we collect two $5 bills.For the next two customers in order, we collect a $10 bill and give back a $5 bill.For the last customer, we can't give change of $15 back because we only have two $10 bills.    Since not every customer received correct change, the answer is false.  My Solution<jupyter_code>def lemonadeChange(b1):
    
    ### 가진 5달러, 10달러, 20달러의 수를 저장합니다.
    cash = {
        5 : 0,
        10 : 0,
        20 : 0,
    }

    ### 총 손님의 수만큼 for문이 돕니다.
    for i in range(len(b1)):
        
        ### 10달러를 받을 경우 10달러 +1, 거스름돈 5달러 -1
        if b1[i] == 10:
            cash[10] += 1
            cash[5] -= 1
            
        ### 가진 5달러가 -1이 되면 False를 반환합니다
        if cash[5] == -1:
            return False
        
        ### 20달러를 받을 경우 경우의 수에 따라 대응합니다. 
        if b1[i] == 20:
            
            ### 10달러와 5달러가 둘 다 있을 경우 거스름돈으로 10달러 -1, 5달러 -1
            if cash[10] > 0 and cash[5] > 0:
                cash[10] -= 1
                cash[5] -=1
                
            ### 그게 아니고 5달러가 2장 초과해 있을 경우 거스름돈으로 5달러 -3
            elif cash[5] > 2:
                cash[5] -= 3
                
            ### 위 두가지 경우 모두 아닐 경우 거스름돈을 줄 수 없으므로 False를 반환합니다.
            else:
                return False
        
        ### 거스름돈을 주고 나서 5달러나 10달러짜리가 -1이 될 경우 False를 반환합니다.
        if cash[5] == -1 or cash[10] == -1:
            return False   
        
        ### 5달러짜리를 받은 경우 그냥 5달러 +1
        if b1[i] == 5:
            cash[5] += 1
    
    ### 위에서 False를 반환하지 않았다면 True를 반환합니다.
    return True
# test code
b1 = [5,5,10,10,20]
lemonadeChange(b1)<jupyter_output><empty_output><jupyter_text>About My Solution    5달러, 10달러, 20달러별로 몇 장 있는지 저장하는 딕셔너리를 만듭니다.    경우의 수에 따라 True와 False를 반환합니다. (위 코드에 표기)    경우의 수를 더 단순화하지 못한 점이 아쉽습니다.  My Result__Runtime__ : 64 ms, faster than 29.79% of Python3 online submissions for Lemonade Change.__Memory Usage__ : 13.4 MB, less than 36.62% of Python3 online submissions for Lemonade Change.  @lee215's Solution<jupyter_code>def lemonadeChange(bills):
    five = ten = 0
    for i in bills:
        if i == 5: 
            five += 1
        elif i == 10: 
            five, ten = five - 1, ten + 1
        elif ten > 0: 
            five, ten = five - 1, ten - 1
        else: five -= 3
        if five < 0: 
            return False
    return True
# test code
bills = [5,5,10]
lemonadeChange(bills)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0867946147235749, 'fraction_numerical': 0.052420509882555144, 'mean_word_length': 1.8979253112033194, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '533608', 'license': 'MIT', 'n_tokens_mistral': 1455, 'n_tokens_neox': 1474, 'n_words': 479, 'path': 'LeetCode/LeetCode_860LemonadeChange.ipynb', 'repo_name': 'foxsayy/python', 'size': '3491'}