Given an array of strings, group anagrams together.

Example:

Input: ["eat", "tea", "tan", "ate", "nat", "bat"],
Output:[   ["ate","eat","tea"],   ["nat","tan"],   ["bat"] ]
Note:All inputs will be in lowercase.The order of your output does not matter.

Solution:

import "strings"
func groupAnagrams(strs []string) [][]string {
    dict := map[string][]string{}
    result := [][]string{}
    for _, str := range strs {
        count := make([]int, 26)
        for i:= 0; i < len(str); i++ {
            count[int(str[i]-'a')]++
        }
        var key strings.Builder
        for i:=0; i < 26; i++ {
            if count[i] == 0 {
                continue
            }
            key.WriteByte(byte(i +'a'))
            key.WriteByte(byte(count[i] + '0'))
        }
        if _,ok := dict[key.String()]; ok != true {
            dict[key.String()] = []string{}
        }
        dict[key.String()] = append( dict[key.String()], str)
    }
    for _,v := range dict {
        result = append(result, v)
    }
    return result
}