Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def isValid(s):
- count = collections.Counter(s)
- values = list(count.values())
- count2 = collections.Counter(values)
- keymaxval = max(count2, key=count2.get)
- del count2[keymaxval]
- #print(count2)
- if len(count2) == 0: return "YES"
- if len(count2) > 1: return 'NO'
- if count2[list(count2.keys())[0]] >= 2: return 'NO'
- if len(count2) == 1:
- if list(count2.keys())[0] == 1:
- return 'YES'
- elif list(count2.keys())[0] - 1 == keymaxval:
- return 'YES'
- else:
- return 'NO'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement