Skip to content

Latest commit

 

History

History
21 lines (19 loc) · 415 Bytes

49.Group_Anagrams.md

File metadata and controls

21 lines (19 loc) · 415 Bytes

49. Group Anagrams

func groupAnagrams(strs []string) [][]string {
	hashtable := make(map[string][]string)
	for _, v := range strs {
		bytes := []byte(v)
		sort.SliceStable(bytes, func(i, j int) bool {
			return bytes[i] < bytes[j]
		})
		s := string(bytes)
		hashtable[s] = append(hashtable[s], v)
	}
	var res [][]string
	for e := range hashtable {
		res = append(res, hashtable[e])
	}
	return res
}