Skip to content

Commit 88fc6a8

Browse files
add 2048
1 parent 34bd5b5 commit 88fc6a8

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|2048|[Next Greater Numerically Balanced Number](https://leetcode.com/problems/next-greater-numerically-balanced-number/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2048.java) ||Medium||
1112
|2047|[Number of Valid Words in a Sentence](https://leetcode.com/problems/number-of-valid-words-in-a-sentence/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2047.java) ||Easy||
1213
|2044|[Count Number of Maximum Bitwise-OR Subsets](https://leetcode.com/problems/count-number-of-maximum-bitwise-or-subsets/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2044.java) ||Medium||
1314
|2043|[Simple Bank System](https://leetcode.com/problems/simple-bank-system/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2043.java) ||Medium||
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class _2048 {
7+
public static class Solution1 {
8+
public int nextBeautifulNumber(int n) {
9+
int ans = n;
10+
do {
11+
ans++;
12+
if (isNumeric(ans)) {
13+
return ans;
14+
}
15+
} while (true);
16+
}
17+
18+
private boolean isNumeric(int number) {
19+
Map<Integer, Integer> map = new HashMap<>();
20+
while (number != 0) {
21+
int digit = number % 10;
22+
map.put(digit, map.getOrDefault(digit, 0) + 1);
23+
number /= 10;
24+
}
25+
for (int key : map.keySet()) {
26+
if (key != map.get(key) || (key == 0 && map.get(key) != 0)) {
27+
return false;
28+
}
29+
}
30+
return true;
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)