Skip to content

Commit ec990b6

Browse files
Merge pull request #2073 from CodingTestStudy2/염혜정
[염혜정] Day22
2 parents 63b84b0 + 5fe998f commit ec990b6

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)