forked from lizeyang18/byteDanceAlgorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest52.java
More file actions
44 lines (40 loc) · 1.08 KB
/
test52.java
File metadata and controls
44 lines (40 loc) · 1.08 KB
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
37
38
39
40
41
42
43
44
package byteDance;
import java.util.HashMap;
/**
* @Author:lizeyang
* @Date:2020/5/23 15:57
* function:柠檬水找零(leetcode 860)
*/
public class test52 {
public static boolean lemonadeChange(int[] bills) {
int bill5 = 0, bill10 = 0, bill20 = 0;
for (int bill : bills) {
if (bill == 5) {
bill5++;
} else if (bill == 10) {
if (bill5 >= 1) {
bill5--;
} else {
return false;
}
bill10++;
} else if (bill == 20) {
if (bill10 >= 1 && bill5 >= 1) {
bill10--;
bill5--;
} else if (bill5 >= 3) {
bill5 -= 3;
} else {
return false;
}
bill20++;
}
}
return true;
}
public static void main(String[] args) {
// int[] bills = {5, 5, 5, 10, 20};
int[] bills = {5};
System.out.println(lemonadeChange(bills));
}
}