An abbreviation of a word follows the form firstletter number lastletter. Below are some examples of word abbreviations:
Question
1 | a) it --> it (no abbreviation) |
1 | 1 |
1 | 1 1 1 |
1 | 1 |
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”) -> false
isUnique(“cart”) -> true
isUnique(“cane”) -> false
isUnique(“make”) -> true
Solution
通过字典构造hashtable,key是单词缩写,value是原单词,通过单词缩写查找是否存在该单词或者单词是否就是本身来判断是否唯一
代码后面补充