Skip to content

Commit

Permalink
Create solution.java
Browse files Browse the repository at this point in the history
  • Loading branch information
adityaranjan2005 authored Aug 15, 2024
1 parent e213706 commit 9bf9e05
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Lemonade Change/solution.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Solution {
public boolean lemonadeChange(int[] bills) {
int five_dollars = 0, ten_dollars = 0;

for (int x : bills) {
if (x == 5) {
five_dollars++;
} else if (x == 10) {
if (five_dollars > 0) {
five_dollars--;
ten_dollars++;
} else {
return false;
}
} else {
if (five_dollars > 0 && ten_dollars > 0) {
five_dollars--;
ten_dollars--;
} else if (five_dollars > 2) {
five_dollars -= 3;
} else {
return false;
}
}
}

return true;
}
}

0 comments on commit 9bf9e05

Please sign in to comment.