Note: Wrong approach. Good lessons though!
(strs []string)
| 70 | |
| 71 | // Note: Wrong approach. Good lessons though! |
| 72 | func 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 | |
| 94 | func isAnagram(s1, s2 string) bool { |
| 95 | if len(s1) == 0 && len(s2) == 0 { |
nothing calls this directly
no test coverage detected