Created
July 24, 2018 11:56
-
-
Save luojiyin1987/2905989802cd16cde3fcad509e626dba to your computer and use it in GitHub Desktop.
Lemonade Change
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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