leetcode - 49. Group Anagrams

在这里插入图片描述

class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        string s;
        vector<vector<string>> ret;
        vector<string> num(1,"");
        unordered_map<string,int>map;
        for(auto it:strs)
        {
            s=it;
            sort(s.begin(),s.end());
            if(map.count(s))
            {
                ret[map[s]].push_back(it);
            }else{
                map[s]=ret.size();
                num[0]=it;
                ret.push_back(num);
            }
        }
        return ret;
    }
};

猜你喜欢

转载自blog.csdn.net/weixin_41938758/article/details/89074703
今日推荐