funcgroupAnagrams(strs []string) [][]string { groups := make(map[string][]string)
for _, word := range strs { chars := []byte(word) sort.Slice(chars, func(i, j int)bool { return chars[i] < chars[j] }) key := string(chars)
groups[key] = append(groups[key], word) }
var results [][]string for _, words := range groups { var sames []string for _, word := range words { sames = append(sames, word) } results = append(results, sames) } return results }
funcgroupAnagrams(strs []string) [][]string { groups := make(map[[26]int][]string)
for _, word := range strs { var key [26]int for _, char := range word { key[int(char - 'a')] += 1 }
groups[key] = append(groups[key], word) }
var results [][]string for _, words := range groups { var sames []string for _, word := range words { sames = append(sames, word) } results = append(results, sames) } return results }