1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
package main
import (
"fmt"
)
func equal(x, y map[string]int) bool {
if len(x) != len(y) {
return false
}
for k, xv := range x {
if yv, ok := y[k]; !ok || yv != xv {
return false
}
}
return true
}
func isAnagram(s string, t string) bool {
m1 := make(map[string]int)
m2 := make(map[string]int)
for _, i := range s {
m1[string(i)]++
}
for _, j := range t {
m2[string(j)]++
}
return equal(m1, m2)
// return reflect.DeepEqual(m1, m2)
}
func main() {
s := "hello"
t := "lelho"
// isAnagram(s, t)
fmt.Println(isAnagram(s, t))
}
|