# 788. Rotated Digits

788. Rotated Digits

```class Solution {
public static int rotatedDigits(int N) {

int good = N;
for (int i = 1; i <= N; i++) {
boolean valid = true;
int current = i;
int converted = i;
inner: {
int m = 1;
while (current != 0) {
int digit = current % 10; // get current digit

// Convert digits regard to the specific rule
if (digit == 2) {
converted -= (digit * m);
converted += (5 * m);
} else if (digit == 5) {
converted -= (digit * m);
converted += (2 * m);
} else if (digit == 6) {
converted -= (digit * m);
converted += (9 * m);
} else if (digit == 9) {
converted -= (digit * m);
converted += (6 * m);
}

if (digit == 3 || digit == 4 || digit == 7) {
valid = false;
good--;
break inner;
}
current /= 10;
m *= 10;// next digit
}

}
if (converted == i && valid)
good--;
}
return good;
}
}
```

# 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;
}
}
```