Created
January 6, 2021 13:50
-
-
Save wkdalsgh192/36ee72824687e90a040e5572c7f564c2 to your computer and use it in GitHub Desktop.
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
| /* | |
| https://leetcode.com/problems/lemonade-change/ | |
| */ | |
| class Solution { | |
| public boolean lemonadeChange(int[] bills) { | |
| int c1=0,c2=0,c3=0; | |
| boolean flag = true; | |
| for(int i=0;i<bills.length;i++) { | |
| switch (bills[i]) { | |
| case 5: | |
| c1++; | |
| break; | |
| case 10: | |
| if (c1>0) { | |
| c2++; | |
| c1--; | |
| } | |
| else return flag=false; | |
| break; | |
| case 20: | |
| if (c1 > 0 && c2 > 0) { | |
| c1-=1; | |
| c2-=1; | |
| c3++; | |
| } | |
| else if (c1 > 2) { | |
| c1 -= 3; | |
| c3++; | |
| } | |
| else { | |
| return flag=false; | |
| } | |
| break; | |
| } | |
| } | |
| return flag; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment