LeetCode-288-Unqiue-Word-Abberviation

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
2
     1
b) d|o|g --> d1g
1
2
3
              1    1  1
1---5----0----5--8
c) i|nternationalizatio|n --> i18n
1
2
3
              1
1---5----0
d) l|ocalizatio|n --> l10n

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是原单词,通过单词缩写查找是否存在该单词或者单词是否就是本身来判断是否唯一

代码后面补充

原创技术分享,您的支持将鼓励我继续创作