```
string originalDigits(string s) {
unordered_map<char, int> freq; for (char c:s) freq[c]++; // get frequency count for s
int count[10] = {freq['z'], freq['o']-freq['z']-freq['w']-freq['u'], freq['w'], freq['h']-freq['g'], // 0~3
freq['u'], freq['f']-freq['u'], freq['x'], freq['s']-freq['x'], // 4~7
freq['g'], freq['i']-freq['g']-freq['x']-freq['f']+freq['u']}; // 8~9
string res; for (int i = 0; i < 10; i++) res += string(count[i], '0'+i); return res; // build result
}
```

**The problem can be translated to a math problem of vector equation:**

- Let 26-D vector sequence {
**w**_{i=0:9}} be the char frequency vector of English words "zero" ~ "nine". for a given 26-D vector**b**, find solution { x_{i=0:9}} to solve vector equation- Σ
_{i=0:9}x_{i}**w**_{i}=**b**. (assume it has a solution)

- Σ

It is a 26-linear-equation system with only 10 variables which is usually over specified to have no solution, but the key is that **the problem guarantees to have a solution**.

Key observation:

- Only unique vector, i.e.,
**w**_{0},**w**_{2},**w**_{6},**w**_{8}has 1 at component`z, w, u, x, g`

, respectively; others have 0. So immediately we have solution of 5 components:- x
_{0}=**b**[z], x_{2}=**b**[w], x_{4}=**b**[u], x_{6}=**b**[x], x_{8}=**b**[g].

- x
- Look at components
`o, h, f, s, i`

of the vector equations, we have- x
_{0}+ x_{1}+ x_{2}+ x_{4}=**b**[o], - x
_{3}+ x_{8}=**b**[h], - x
_{4}+ x_{5}=**b**[f], - x
_{6}+ x_{7}=**b**[s], - x
_{5}+ x_{6}+ x_{8}+ x_{9}=**b**[i].

- x

Combining all equations above, we have the full solution:

- x
_{0}=**b**[z], - x
_{1}=**b**[o] -**b**[z] -**b**[w] -**b**[u], - x
_{2}=**b**[w], - x
_{3}=**b**[h] -**b**[g], - x
_{4}=**b**[u], - x
_{5}=**b**[f] -**b**[u], - x
_{6}=**b**[x], - x
_{7}=**b**[s] -**b**[x],, - x
_{8}=**b**[g], - x
_{9}=**b**[i] -**b**[g] -**b**[x] -**b**[f] +**b**[u].