Skip to content

Commit 9bf9e05

Browse files
Create solution.java
1 parent e213706 commit 9bf9e05

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

Lemonade Change/solution.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution {
2+
public boolean lemonadeChange(int[] bills) {
3+
int five_dollars = 0, ten_dollars = 0;
4+
5+
for (int x : bills) {
6+
if (x == 5) {
7+
five_dollars++;
8+
} else if (x == 10) {
9+
if (five_dollars > 0) {
10+
five_dollars--;
11+
ten_dollars++;
12+
} else {
13+
return false;
14+
}
15+
} else {
16+
if (five_dollars > 0 && ten_dollars > 0) {
17+
five_dollars--;
18+
ten_dollars--;
19+
} else if (five_dollars > 2) {
20+
five_dollars -= 3;
21+
} else {
22+
return false;
23+
}
24+
}
25+
}
26+
27+
return true;
28+
}
29+
}

0 commit comments

Comments
 (0)