add new solutions
This commit is contained in:
parent
d798d5e8c9
commit
886b5e0a8e
34 changed files with 1164 additions and 0 deletions
22
solutions/0/q49/solution.go
Normal file
22
solutions/0/q49/solution.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package q49
|
||||
|
||||
import "slices"
|
||||
|
||||
func groupAnagrams(strs []string) [][]string {
|
||||
groups := map[string][]string{}
|
||||
|
||||
for i := range strs {
|
||||
byt := []byte(strs[i])
|
||||
slices.Sort(byt)
|
||||
sorted := string(byt)
|
||||
groups[sorted] = append(groups[sorted], strs[i])
|
||||
}
|
||||
|
||||
ret := make([][]string, 0, len(groups))
|
||||
for _, g := range groups {
|
||||
ret = append(ret, g)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
var _ = groupAnagrams
|
||||
Loading…
Add table
Add a link
Reference in a new issue