-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path860.lemonade-change.java
More file actions
37 lines (34 loc) · 862 Bytes
/
860.lemonade-change.java
File metadata and controls
37 lines (34 loc) · 862 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
/*
* @lc app=leetcode id=860 lang=java
*
* [860] Lemonade Change
*/
// @lc code=start
class Solution {
public boolean lemonadeChange(int[] bills) {
int fiveNum = 0;
int tenNum = 0;
for (int i = 0; i < bills.length; i++) {
if (bills[i] == 5) {
fiveNum++;
}
if (bills[i] == 10) {
if (fiveNum == 0) return false;
fiveNum--;
tenNum++;
}
if (bills[i] == 20) {
if (fiveNum > 0 && tenNum > 0) {
fiveNum--;
tenNum--;
} else if (tenNum == 0 && fiveNum >= 3) {
fiveNum -= 3;
} else {
return false;
}
}
}
return true;
}
}
// @lc code=end