forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_2048.java
33 lines (30 loc) · 900 Bytes
/
_2048.java
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
package com.fishercoder.solutions;
import java.util.HashMap;
import java.util.Map;
public class _2048 {
public static class Solution1 {
public int nextBeautifulNumber(int n) {
int ans = n;
do {
ans++;
if (isNumeric(ans)) {
return ans;
}
} while (true);
}
private boolean isNumeric(int number) {
Map<Integer, Integer> map = new HashMap<>();
while (number != 0) {
int digit = number % 10;
map.put(digit, map.getOrDefault(digit, 0) + 1);
number /= 10;
}
for (int key : map.keySet()) {
if (key != map.get(key) || (key == 0 && map.get(key) != 0)) {
return false;
}
}
return true;
}
}
}