題目:
思路:用map來存異位詞,
代碼:
class Solution {
unordered_map<string, vector<string>> m;
public:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
vector<vector<string>> ans;
for (auto e : strs){
string tt = e;
std::sort(e.begin(), e.end());
m[e].push_back(tt);
}
for (auto e : m){
ans.push_back(e.second);
}
return ans;
}
};
----
2020.4.7 第4題