Description
Submission
class Solution {
int cnt[10];
public:
string originalDigits(string s) {
map<char, int> freq;
for(char ch: s) {
++freq[ch];
}
cnt[8] = freq['g'];
cnt[4] = freq['u'];
cnt[2] = freq['w'];
cnt[6] = freq['x'];
cnt[0] = freq['z'];
cnt[1] = freq['o'] - cnt[0] - cnt[2] - cnt[4];
cnt[3] = freq['h'] - cnt[8];
cnt[5] = freq['f'] - cnt[4];
cnt[7] = freq['s'] - cnt[6];
cnt[9] = (freq['n'] - cnt[1] - cnt[7]) / 2;
string ret;
for(int i = 0 ; i < 10; ++i) {
if(cnt[i]) ret += string(cnt[i], '0' + i);
}
return ret;
}
};
// { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
// e: zero, one, three, five, seven, eight, nine
// g: eight
// f: four, five
// i: five, six, eight, nine
// h: three, eight
// o: zero, one, two, four
// n: one, seven, nine
// s: six, seven
// r: zero, three
// u: four
// t: two, three, eight
// w: two
// v: five, seven
// x: six
// z: zero