python solution


  • 0
    B
    class Solution(object):
        def originalDigits(self, s):
            """
            :type s: str
            :rtype: str
            """
            ss=collections.Counter(s)
            tmp=['z','o','w','t','u','f','x','s','g','i']
            i=0
            ans=''
            while i<len(tmp):
                if i%2==0 and tmp[i] in ss:
                    for j in range(ss[tmp[i]]):
                        ans+="%s"%i
                elif  i%2==1 and tmp[i] in ss:
                    if tmp[i]=='o':
                        n=ss[tmp[i]]-ss[tmp[0]]-ss[tmp[2]]-ss[tmp[4]]
                    elif tmp[i]=='t':
                        n=ss[tmp[i]]-ss[tmp[2]]-ss[tmp[8]]
                    elif tmp[i]=='f':
                       n=ss[tmp[i]]-ss[tmp[4]]
                    elif tmp[i]=='s':
                       n=ss[tmp[i]]-ss[tmp[6]]
                    elif tmp[i]=='i':
                       n=ss[tmp[i]]-ss[tmp[6]]-ss[tmp[8]]-ss['f']+ss[tmp[4]]
                    for j in range(n):
                        ans+="%s"%i
                i+=1
            return ans
    

Log in to reply
 

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