forked from javadev/LeetCode-in-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.java
32 lines (30 loc) · 922 Bytes
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package g0801_0900.s0860_lemonade_change;
// #Easy #Array #Greedy #Programming_Skills_II_Day_17
// #2022_03_27_Time_2_ms_(90.84%)_Space_75.8_MB_(55.09%)
public class Solution {
public boolean lemonadeChange(int[] bills) {
int countFive = 0;
int countTen = 0;
for (int bill : bills) {
if (bill == 5) {
countFive++;
} else if (bill == 10) {
if (countFive == 0) {
return false;
}
countFive--;
countTen++;
} else if (bill == 20) {
if (countFive > 0 && countTen > 0) {
countFive--;
countTen--;
} else if (countFive >= 3) {
countFive -= 3;
} else {
return false;
}
}
}
return true;
}
}