fork download
  1. class Solution(object):
  2. def minDeletions(self, s):
  3. """
  4. :type s: str
  5. :rtype: int
  6. """
  7.  
  8. freq_map = {}
  9. count = 0
  10. unique_val = []
  11. # hash freq map
  12. for char in s:
  13. if char not in freq_map:
  14. freq_map[char] = 0
  15. freq_map[char] += 1
  16.  
  17. #
  18. for char in freq_map:
  19. while freq_map[char] > 0 and freq_map[char] in unique_val:
  20. count += 1
  21. freq_map[char] -= 1
  22. if freq_map[char] not in unique_val:
  23. unique_val.append(freq_map[char])
  24. return count
  25.  
  26.  
  27.  
Success #stdin #stdout 0.02s 9104KB
stdin
Standard input is empty
stdout
Standard output is empty