-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLemonadeChange.java
More file actions
34 lines (33 loc) · 818 Bytes
/
LemonadeChange.java
File metadata and controls
34 lines (33 loc) · 818 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
//860. Lemonade Change
class Solution {
public boolean lemonadeChange(int[] bills) {
int five = 0;
int ten = 0;
for(int i = 0; i < bills.length; i++){
if(bills[i] == 5){
five++;
}
if(bills[i] == 10){
if(five > 0){
ten++;
five--;
}else{
return false;
}
}
if(bills[i] == 20){
if(five > 0 && ten > 0){
five--;
ten--;
}
else if(five >= 3){
five = five - 3;
}
else{
return false;
}
}
}
return true;
}
}