Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. def isValid(s):
  2. count = collections.Counter(s)
  3. values = list(count.values())
  4. count2 = collections.Counter(values)
  5. keymaxval = max(count2, key=count2.get)
  6. del count2[keymaxval]
  7. #print(count2)
  8. if len(count2) == 0: return "YES"
  9. if len(count2) > 1: return 'NO'
  10. if count2[list(count2.keys())[0]] >= 2: return 'NO'
  11. if len(count2) == 1:
  12. if list(count2.keys())[0] == 1:
  13. return 'YES'
  14. elif list(count2.keys())[0] - 1 == keymaxval:
  15. return 'YES'
  16. else:
  17. return 'NO'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement