-
Notifications
You must be signed in to change notification settings - Fork 0
/
leet_code_102.py
17 lines (16 loc) · 1.06 KB
/
leet_code_102.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#https://leetcode.com/problems/remove-letter-to-equalize-frequency/
#Remove Letter To Equalize Frequency
#You are given a 0-indexed string word, consisting of lowercase English letters.
#You need to select one index and remove the letter at that index from word so that the frequency of every letter present in word is equal.
#Return true if it is possible to remove one letter so that the frequency of all letters in word are equal, and false otherwise.
#Note:
#The frequency of a letter x is the number of times it occurs in the string.
#You must remove exactly one letter and cannot chose to do nothing.
#Input: word = "abcc"
#Output: true
#Explanation: Select index 3 and delete it: word becomes "abc" and each character has a frequency of 1.
#Input: word = "aazz"
#Output: false
#Explanation: We must delete a character, so either the frequency of "a" is 1 and
#the frequency of "z" is 2, or vice versa. It is impossible to make all present letters have equal frequency.
['True' if a.count(2)==1 else 'False' for i in set([word.count(word[i]) for i in range(len(set(word)))])]