MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / groupAnagrams

Function groupAnagrams

group_anagrams_49/solution.go:12–25  ·  view source on GitHub ↗

Third solution based on creating identical encoding for strings that are anagrams of each other for grouping.

(strs []string)

Source from the content-addressed store, hash-verified

10// Third solution based on creating identical encoding for
11// strings that are anagrams of each other for grouping.
12func groupAnagrams(strs []string) [][]string {
13 groupMap := make(map[string][]string)
14 for _, s := range strs {
15 se := encodeString(s)
16 groupMap[se] = append(groupMap[se], s)
17 }
18
19 groups := make([][]string, 0)
20 for _, v := range groupMap {
21 groups = append(groups, v)
22 }
23
24 return groups
25}
26
27func encodeString(s string) string {
28 chars := make([]int, 26)

Callers 1

Test_groupAnagramsFunction · 0.85

Calls 1

encodeStringFunction · 0.85

Tested by 1

Test_groupAnagramsFunction · 0.68