Python | Leetcode Python题解之第423题从英文中重建数字
题目:
题解:
class Solution:def originalDigits(self, s: str) -> str:c = Counter(s)cnt = [0] * 10cnt[0] = c["z"]cnt[2] = c["w"]cnt[4] = c["u"]cnt[6] = c["x"]cnt[8] = c["g"]cnt[3] = c["h"] - cnt[8]cnt[5] = c["f"] - cnt[4]cnt[7] = c["s"] - cnt[6]cnt[1] = c["o"] - cnt[0] - cnt[2] - cnt[4]cnt[9] = c["i"] - cnt[5] - cnt[6] - cnt[8]return "".join(str(x) * cnt[x] for x in range(10))