MCPcopy Create free account
hub / github.com/Ainevsia/Leetcode-Rust / groupAnagrams

Method groupAnagrams

49. Group Anagrams/Solution.cpp:19–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17
18public:
19 vector<vector<string>> groupAnagrams(vector<string>& strs) {
20 vector<unsigned long> hash;
21 vector<vector<string>> res;
22 for (string str : strs) {
23 unsigned s_hash = getHash(str);
24 bool found = false;
25 for (int i = 0; i < hash.size(); i ++) {
26 if (hash[i] == s_hash) {
27 res[i].push_back(str);
28 found = true;
29 break;
30 }
31 }
32 if (not found) {
33 hash.push_back(s_hash);
34 res.push_back({str});
35 }
36 }
37 return res;
38 }
39
40 unsigned long getHash(string str) {
41 int cnt[26] = {0};

Callers 1

mainFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected