An abbreviation of a word follows the form . Below are some examples of word abbreviations:
a) it? ? ? ? ? ? ? ? ? ? ? --> it? ? (no abbreviation)
b) 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 nootherword from the dictionary has the same abbreviation.
Example:
Given dictionary = [ "deer", "door", "cake", "card" ]
isUnique("dear") ->false
isUnique("cart") ->true
isUnique("cake") ->true
isUnique("make") ->true
這個(gè)題用hashmap 很簡(jiǎn)單瘤睹, 但是要注意一點(diǎn)橘沥, 如果dictionary 里有個(gè)cake骆捧, 唯一一個(gè)c2e 那么橙依, 問cake的時(shí)候要返回true, 所以說 要把抽象字符筛严, 和字符 存儲(chǔ)起來杂穷, 如果字符唯一, 那么要存起來雁乡, 字符不唯一第喳, 要把里面剛剛存的用空串清除掉
if(map.containsKey(key) && !map.get(key).equals(str)){
? ? ? map.put(key, "");
}
這段代碼是關(guān)鍵糜俗!