LeetCode--Anagrams

来源:互联网 发布:颈椎牵引知乎 编辑:程序博客网 时间:2024/04/29 18:18
class Solution {public:    vector<string> anagrams(vector<string> &strs) {        vector<string> res;        map<string, vector<string>> strmap;                int size = strs.size();        for(auto it=strs.begin(); it!=strs.end(); it++)        {            string s = *it;            sort(s.begin(), s.end());            strmap[s].push_back(*it);        }                for(auto it=strmap.begin(); it!=strmap.end(); it++)        {            if(it->second.size() > 1)                res.insert(res.end(), it->second.begin(), it->second.end());        }        return res;    }};

0 0