fork download
  1. class Solution(object):
  2. def maxDifference(self, s):
  3. dicti = {}
  4. for c in s:
  5. if c not in dicti:
  6. dicti[c] = 0
  7. dicti[c] +=1
  8. evenChars = []
  9. oddChars = []
  10. for key in dicti:
  11. if dicti[key] % 2 == 0:
  12. evenChars.append(key)
  13. else:
  14. oddChars.append(key)
  15.  
  16. evenChars = sorted(evenChars, key=lambda x:dicti[x])
  17. oddChars = sorted(oddChars, key=lambda x:dicti[x])
  18. return dicti[oddChars[-1]] - dicti[evenChars[0]]
Success #stdin #stdout 0.11s 14108KB
stdin
Standard input is empty
stdout
Standard output is empty