mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-08-21 10:42:07 +00:00
update
This commit is contained in:
parent
3433533b24
commit
dc144b3046
@ -1,3 +1,6 @@
|
||||
#include <algorithm>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include<vector>
|
||||
#include<string>
|
||||
using namespace std;
|
||||
@ -5,7 +8,17 @@ using namespace std;
|
||||
class Solution {
|
||||
public:
|
||||
vector<vector<string>> groupAnagrams(vector<string>& strs) {
|
||||
|
||||
unordered_map<string, vector<string>> m;
|
||||
for(int i=0;i<strs.size();i++){
|
||||
string ns=strs[i];
|
||||
sort(ns.begin(),ns.end());
|
||||
m[ns].push_back(std::move(strs[i]));
|
||||
}
|
||||
vector<vector<string>> ans;
|
||||
for(auto s :m){
|
||||
ans.push_back(std::move(s.second));
|
||||
}
|
||||
return ans;
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user