49. 字母异位词分组

 1 class Solution 
 2 {
 3 public:
 4     vector<vector<string>> groupAnagrams(vector<string>& strs) 
 5     {
 6         vector<vector<string>> res;
 7         unordered_map<string,vector<string>> hash;
 8         for(auto a : strs)
 9         {
10             string temp = a;
11             sort(temp.begin(),temp.end());
12             hash[temp].push_back(a);
13         }
14         for(auto h : hash)
15         {
16             res.push_back(h.second);
17         }
18         return res;
19     }
20 };

 

posted @ 2020-03-18 18:14  Jinxiaobo0509  阅读(75)  评论(0)    收藏  举报