Tag:leetcode fb array
Category:Leetcode
Article From:https://www.cnblogs.com/JTechRoad/p/9060064.html

https://leetcode.com/problems/group-anagrams/description/

class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        unordered_map<string,multiset<string>> m;
        for (auto s : strs) {
            string ss = s;
            sort(ss.begin(), ss.end());
            m[ss].insert(s);
        }
        vector<vector<string>> res;
        for (const auto& p : m) {
            vector<string> v;
            for (const auto& s : p.second)
                v.push_back(s);
            res.push_back(v);
        }
        return res;
    }
};

 

Link of this Article: 49. Group Anagrams

Leave a Reply

Your email address will not be published. Required fields are marked *