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

Function groupAnagrams0

group_anagrams_49/solution.go:72–92  ·  view source on GitHub ↗

Note: Wrong approach. Good lessons though!

(strs []string)

Source from the content-addressed store, hash-verified

70
71// Note: Wrong approach. Good lessons though!
72func groupAnagrams0(strs []string) [][]string {
73 groups := make([][]string, 0)
74 seen := make(map[string]bool)
75 for i := 0; i < len(strs); i++ {
76 _, ok := seen[strs[i]]
77 if ok && strs[i] != "" {
78 continue
79 }
80 group := make([]string, 1)
81 group[0] = strs[i]
82 for j := i + 1; j < len(strs); j++ {
83 _, ok := seen[strs[j]]
84 if !ok && isAnagram(strs[i], strs[j]) {
85 group = append(group, strs[j])
86 seen[strs[j]] = true
87 }
88 }
89 groups = append(groups, group)
90 }
91 return groups
92}
93
94func isAnagram(s1, s2 string) bool {
95 if len(s1) == 0 && len(s2) == 0 {

Callers

nothing calls this directly

Calls 1

isAnagramFunction · 0.70

Tested by

no test coverage detected