-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLemonadeChange.java
More file actions
50 lines (47 loc) · 1.31 KB
/
LemonadeChange.java
File metadata and controls
50 lines (47 loc) · 1.31 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
45
46
47
48
49
50
package Leetcode;
import java.util.Stack;
/**
* @author szh
* @create 2018-08-14 23:31
**/
public class LemonadeChange {
public boolean lemonadeChange(int[] bills) {
Stack<Integer> five =new Stack<>();
Stack<Integer> ten =new Stack<>();
int[] money =new int[bills.length];
for(int i =0 ;i<=bills.length ;i++){
if(bills[i] == 5){
five.push(bills[i]);
}
if(bills[i] == 10){
ten.push(bills[i]);
if(five.size() == 0){
return false;
}
five.pop();
}
if(bills[i] == 20){
if(five.size() == 0){
return false;
}
if(ten.size() == 0){
if(five.size() >=3){
five.pop();
five.pop();
five.pop();
}else{
return false;
}
}else{
ten.pop();
five.pop();
}
}
}
return true;
}
public static void main(String[] args) {
int[] a= new int[]{5,5,5,10,5,5,10,20,20,20};
new LemonadeChange().lemonadeChange(a);
}
}