Untitled

 avatar
unknown
plain_text
2 years ago
541 B
2
Indexable
class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        unordered_map<string,vector<string>>m;
        vector<vector<string>>ans;
        for(auto x:strs){
            string temp=x;
            sort(x.begin(),x.end());
            //m[x]=temp;
            m[x].push_back(temp);
        }
        for(auto x:m){
            //vector<string>temp=*(x->second); why wrong
            vector<string>temp=x.second;
            ans.push_back(temp);
        }
        return ans;
    }
};
Editor is loading...