Skip to content

Instantly share code, notes, and snippets.

@wkdalsgh192
Created January 6, 2021 13:50
Show Gist options
  • Select an option

  • Save wkdalsgh192/36ee72824687e90a040e5572c7f564c2 to your computer and use it in GitHub Desktop.

Select an option

Save wkdalsgh192/36ee72824687e90a040e5572c7f564c2 to your computer and use it in GitHub Desktop.
/*
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