Python Solution


  • 0
    class Solution(object):
        def originalDigits(self, s):
            f = [0] * 26
            for c in s:
                f[ord(c)-ord('a')] += 1
            h = {'z': ('zero','0'), 'w': ('two','2'), 'x' : ('six','6'), 'g': ('eight','8'), 'h': ('three','3'), 's': ('seven','7'), 'v': ('five','5'), 'f': ('four','4'), 'o': ('one', '1'), 'i': ('nine','9')}
            ans = []
            for x in ['z','w','x','g','h','s','v','f','o','i']:
                word ,num = h[x]
                n = f[ord(x)-ord('a')]
                if n <= 0:
                    continue
                ans += [num] * n
                for c in word:
                    f[ord(c)-ord('a')] -= n
            return ''.join(sorted(ans))

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.