题目来源
题目描述
题目解析
思路
class ValidWordAbbr {
public:
ValidWordAbbr(vector<string>& dictionary) {
for (auto a : dictionary) {
string k = a;
if (a.size() > 2) k = a[0] + to_string(a.size() - 2) + a.back();
m[k].insert(a);
}
}
bool isUnique(string word) {
string k = word;
if (word.size() > 2) k = word[0] + to_string(word.size() - 2) + word.back();
return m[k].count(word) == m[k].size();
}
private:
unordered_map<string, unordered_set<string>> m;
};
这应该是个简单题