1. Description

2. Solution
**解析:**Version 1,找出
0-9
英文字母個數與數字個數的對應關系,然後根據統計的字元數計算對應的數字個數,按順序構造最後的字元串即可。
- Version 1
class Solution:
def originalDigits(self, s: str) -> str:
chars = ["e", "g", "f", "i", "h", "o", "n", "s", "r", "u", "t", "w", "v", "x", "z"]
stat = {ch: 0 for ch in chars}
for ch in s:
stat[ch] += 1
result = ''
result += '0' * stat['z']
result += '1' * (stat['o'] - stat['z'] - stat['w'] - stat['u'])
result += '2' * stat['w']
result += '3' * (stat['r'] - stat['z'] - stat['u'])
result += '4' * stat['u']
result += '5' * (stat['f'] - stat['u'])
result += '6' * stat['x']
result += '7' * (stat['v'] - (stat['f'] - stat['u']))
result += '8' * stat['g']
result += '9' * (stat['i'] - (stat['f'] - stat['u']) - stat['x'] - stat['g'])
return result
複制
Reference
- https://leetcode.com/problems/reconstruct-original-digits-from-english/