forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.java
29 lines (26 loc) · 902 Bytes
/
Solution.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
class Solution {
public String originalDigits(String s) {
int[] counter = new int[26];
for (char c : s.toCharArray()) {
++counter[c - 'a'];
}
int[] cnt = new int[10];
cnt[0] = counter['z' - 'a'];
cnt[2] = counter['w' - 'a'];
cnt[4] = counter['u' - 'a'];
cnt[6] = counter['x' - 'a'];
cnt[8] = counter['g' - 'a'];
cnt[3] = counter['h' - 'a'] - cnt[8];
cnt[5] = counter['f' - 'a'] - cnt[4];
cnt[7] = counter['s' - 'a'] - cnt[6];
cnt[1] = counter['o' - 'a'] - cnt[0] - cnt[2] - cnt[4];
cnt[9] = counter['i' - 'a'] - cnt[5] - cnt[6] - cnt[8];
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10; ++i) {
for (int j = 0; j < cnt[i]; ++j) {
sb.append(i);
}
}
return sb.toString();
}
}