-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL860.java
More file actions
36 lines (33 loc) · 996 Bytes
/
L860.java
File metadata and controls
36 lines (33 loc) · 996 Bytes
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
33
34
35
36
package LeetCode;
class LemonadeChange {
public static boolean lemonadeChange(int[] bills) {
int fiveCount = 0;
int tenCount = 0;
for (int bill : bills) {
if (bill == 5) {
fiveCount++;
} else if (bill == 10) {
if (fiveCount == 0) {
return false;
}
fiveCount--;
tenCount++;
} else if (bill == 20) {
if (tenCount > 0 && fiveCount > 0) {
tenCount--;
fiveCount--;
} else if (fiveCount >= 3) {
fiveCount -= 3;
} else {
return false;
}
}
}
return true;
}
public static void main(String[] args) {
int bills[] = {5, 5, 5, 10, 20};
boolean output = lemonadeChange(bills);
System.out.println(output); // This will print: true
}
}