288 Unique Word Abbreviation
288 Unique Word Abbreviation (L648)
An abbreviation of a word follows the form. Below are some examples of word abbreviations:
Assume you have a dictionary and given a word, find whether its abbreviation is unique in the dictionary. A word's abbreviation is unique if no other word from the dictionary has the same abbreviation.
Example
Given dictionary =[ "deer", "door", "cake", "card" ]
isUnique("dear") // return false
isUnique("cart") // return true
isUnique("cane") // return false
isUnique("make") // return true
这题要注意的是如果字典中有多个cake出现,那么当判断isUnique的时候是否返回true。这个题需要跟面试官讨论。这里我们假设是, 就是如果字典有["cake", "cake"] isUnique("cake")返回true。我们可以发现,如果字典中某单词出现的个数跟abbr之后出现的个数相同的话,证明这个词的abbr是unique的。
PreviousL659 Encode and Decode StringsNext443 String Compression & ctci189 1 point 6 String Compression
Last updated