找规律
所有偶数天生唯一字符标识
zero z
two w
four u
six x
eight g
然后这几个先找完(删除)以后剩下的奇数又可以开心的唯一字符了
seven s
five f
one o
three h
nine i
def originalDigits(self, s: str) -> str:
cnt = Counter(s)
digits = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
freq = [0]*10
for x, i in ("z", 0), ("w", 2), ("u", 4), ("x", 6), ("g", 8), ("s", 7), ("f", 5), ("o", 1), ("h", 3), ("i", 9):
freq[i] += cnt[x]
cnt -= Counter(digits[i]*cnt[x])
return "".join(str(i)*x for i, x in enumerate(freq))
摘自评论区 – 是上帝创造的数字么?上帝喜欢(选择)偶数?