Untitled

mail@pastecode.io avatar
unknown
plain_text
24 days ago
424 B
1
Indexable
Never
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;
    }
};
Leave a Comment