Created
July 24, 2018 15:53
-
-
Save luojiyin1987/35600b38168b8dc6271d931a72b86640 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
| func lemonadeChange(bills []int) bool { | |
| numFive :=0 | |
| numTen :=0 | |
| numTwenty :=0 | |
| for i := range bills { | |
| switch bills[i] { | |
| case 5: | |
| numFive +=1 | |
| case 10 : | |
| if numFive >=1 { | |
| numTen += 1 | |
| numFive -= 1 | |
| } else{ | |
| return false | |
| } | |
| case 20: | |
| if numTen >=1 && numFive >=1 { | |
| numTen -= 1 | |
| numFive -= 1 | |
| } else if numFive >= 3 { | |
| numFive -= 3 | |
| } else { | |
| return false | |
| } | |
| } | |
| } | |
| return numFive >=0 && numTen >= 0 && numTwenty >= 0 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment