Skip to content

Instantly share code, notes, and snippets.

@luojiyin1987
Created July 24, 2018 11:56
Show Gist options
  • Save luojiyin1987/2905989802cd16cde3fcad509e626dba to your computer and use it in GitHub Desktop.
Save luojiyin1987/2905989802cd16cde3fcad509e626dba to your computer and use it in GitHub Desktop.
Lemonade Change
class Solution:
def lemonadeChange(self, bills):
"""
:type bills: List[int]
:rtype: bool
"""
numFive = 0
numTen = 0
numTwenty = 0
for bill in bills:
if bill == 5:
numFive+= 1
print(numFive, numTen, numTwenty)
elif bill == 10 and (numFive>=1) :
numFive -= 1
numTen += 1
print(numFive, numTen, numTwenty)
elif bill == 20 and ((numTen>=1 and numFive >=1) or numFive>=3):
numTwenty +=1
if numTen >=1 and numFive>=1:
numFive -=1
numTen -=1
elif numFive >=3:
numFive -=3
else:
return False
return (numFive >=0 and numTen >= 0 and numTwenty >=0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment