Skip to content

Commit 865bd48

Browse files
authored
Create Solution.java
1 parent 0902810 commit 865bd48

File tree

1 file changed

+25
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)