a fun hard coding(O(n), one pass)


  • 0
    E

    """
    def originalDigits(self, s):
    """
    :type s: str
    :rtype: str
    """

        c = collections.Counter(s)
        res = ''
        res += c['u'] * '4'
        c.subtract('four' * c['u'])
        res += c['f'] * '5'
        c.subtract('five' * c['f'])
        res += c['x'] * '6'
        c.subtract('six' * c['x'])
        res += c['v'] * '7'
        c.subtract('seven' * c['v'])
        res += c['g'] * '8'
        c.subtract('eight' * c['g'])
        res += c['i'] * '9'
        c.subtract('nine' * c['i'])
        res = c['h'] * '3' + res
        c.subtract('three' * c['t'])
        res = c['w'] * '2' + res
        c.subtract('two' * c['w'])
        res = c['n'] * '1' + res
        c.subtract('one' * c['n'])
        res = c['z'] * '0' + res
        c.subtract('zero' * c['z'])
        #print c, res
        return res
    

    """


Log in to reply
 

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