class ValidWordAbbr(object): def __init__(self, dictionary): """ initialize your data structure here. :type dictionary: List[str] """ self.dictionary =  for index, word in enumerate(dictionary): abbreviation = word if len(word) > 2: word_length = len(word) abbreviation = word +str(word_length-2) + word[word_length-1] self.dictionary.append(abbreviation) def isUnique(self, word): """ check if a word is unique. :type word: str :rtype: bool """ abbreviation = word if len(word) > 2: word_length = len(word) abbreviation = word + str(word_length-2) + word[word_length-1] if abbreviation in self.dictionary: return False else: return True
Don't understand why this test case fails for the above code.
If the dictionary has the word "hello" in it then "hello" is not unique no? It should return false instead of true?
Input: ["hello"],isUnique("hello") Output: [false] Expected: [true]
It actually is unique -- in this case, it is the only instance of "h3o" in the dictionary. If "hallo" was also in the dictionary, then "hello" would not be unique. Make sense?
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.