LeetCode的一個題目,記錄一個巧妙的解法,剛看到是感覺腦洞大開。以vector<string>作爲value值這是我沒有想到的。
unordered_map<string, vector<string>> dicts;
vector<vector<string>> ret;
for (auto str : strs)
{
string tmp = str;
sort(tmp.begin(), tmp.end());
dicts[tmp].push_back(str);
}
for (const auto& d : dicts)
ret.push_back(d.second);
return ret;