# Group Anagrams ###### tags: `Medium`、`Hash_table` https://leetcode.com/problems/group-anagrams/submissions/  - 大神的寫法 ```cpp= class Solution { public: vector<vector<string>> groupAnagrams(vector<string>& strs) { unordered_map<string, int> htable; vector<vector<string>> result; int next_index = 0; for(int i = 0; i < strs.size(); ++i) { auto str = strs[i]; int cur_index = -1; sort(str.begin(), str.end()); if(htable.find(str) == htable.end()) { htable[str] = next_index; result.emplace_back(vector<string>()); next_index++; } cur_index = htable[str]; result[cur_index].push_back(strs[i]); } return result; } }; ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up