python beat 98.5%


  • 0
    I
    class Solution(object):
        def originalDigits(self, s):
            """
            :type s: str
            :rtype: str
            """
            ret = ""
            numbers = ['zero','two','four','one','six','seven','five','three','eight','nine']
            digits = [0,2,4,1,6,7,5,3,8,9]
            uniqueChar = ['z', 'w','u','o','x','s','f','r','g','i']
            hashtable = {x:s.count(x) for x in ('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')}
            for i in range(0, 10):
                count = hashtable[uniqueChar[i]]
                if count == 0:
                    continue
                ret = ret + str(digits[i])*count
                for c in numbers[i]:
                    hashtable[c] -= count
            return "".join(sorted(ret))
            
    

Log in to reply
 

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