Untitled
unknown
plain_text
2 years ago
424 B
5
Indexable
class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
vector<vector<string>>res;
if(strs.empty()) return res;
unordered_map<string,vector<string>> mp;
for(auto i:strs){
string wrd=i;
sort(wrd.begin(),wrd.end());
mp[wrd].push_back(i);
}
for(auto i:mp) res.push_back(i.second);
return res;
}
};Editor is loading...
Leave a Comment