860. Lemonade Change

class Solution {
public static boolean lemonadeChange(int[] bills) {
HashMap d = new HashMap();
d.put(5, 0);
d.put(10, 0);
for (int i = 0; i < bills.length; i++) {
if (bills[i] == 5) {
d.put(5, d.get(5) + 1);
} else if (bills[i] == 10) {
if (d.get(5) <= 0)
return false;
d.put(5, d.get(5) - 1);
d.put(10, d.get(10) + 1);
} else if (bills[i] == 20) {
if ((d.get(10) - 1) < 0) { // no 10's
if (d.get(5) - 3 < 0)
return false;
} else {// there are 10's
if (d.get(5) - 1 = 1 && d.get(5) >= 1) {
d.put(5, d.get(5) - 1);
d.put(10, d.get(10) - 1);
} else if (d.get(5) - 3 >= 0) {
d.put(5, d.get(5) - 3);
}
}
}
return true;
}
}

### Like this:

Like Loading...

*Related*