Advertisement
Pandaaaa906

Untitled

Jul 5th, 2019
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. from collections import Counter
  2.  
  3. p = (
  4.     ('z', 'zero', 0),
  5.     ('w', 'two', 2),
  6.     ('g', 'eight', 8),
  7.     ('t', 'three', 3),
  8.     ('r', 'four', 4),
  9.     ('x', 'six', 6),
  10.     ('s', 'seven', 7),
  11.     ('o', 'one', 1),
  12.     ('v', 'five', 5),
  13.     ('i', 'nine', 9),
  14. )
  15.  
  16. def func(s):
  17.     c = Counter(s)
  18.     for char, word, num in p:
  19.         n = c.get(char, 0)
  20.         if n == 0:continue
  21.         tmp = Counter(word)
  22.         for i in range(n):
  23.             c -= tmp
  24.         yield n
  25.  
  26. class Solution:
  27.     def originalDigits(self, s: str) -> str:
  28.         return "".join(map(str, sorted(list(func(s)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement