Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def equalFrequency(self, word: str) -> bool:
- count: list = []
- for i in set(word):
- count.append(word.count(i))
- if len(count) == 1 and count[0] != 1:
- return True
- x = max(count)
- y = min(count)
- if y == x == 1:
- return True
- count_of_x = 0
- count_of_y = 0
- for i in count:
- if i == x:
- count_of_x += 1
- if i == y:
- count_of_y += 1
- if count_of_x > 1 and count_of_y != 1:
- return False
- counts: set = set(count)
- if len(counts) != 2:
- return False
- if min(counts) == max(counts) - 1 and count_of_x == 1:
- return True
- if min(counts) == 1 and count_of_y == 1:
- return True
- return False
Advertisement
Add Comment
Please, Sign In to add comment