File tree Expand file tree Collapse file tree 2 files changed +22
-29
lines changed Expand file tree Collapse file tree 2 files changed +22
-29
lines changed Original file line number Diff line number Diff line change 2
2
package main
3
3
4
4
func isAnagram (s string , t string ) bool {
5
- if len (s ) != len (t ) {
6
- return false
5
+ var frequency [26 ]int
6
+ for _ , r := range s {
7
+ frequency [r - 'a' ]++
7
8
}
8
-
9
- var freq [26 ]int
10
- for i := 0 ; i < len (s ); i ++ {
11
- freq [s [i ]- 'a' ]++
12
- freq [t [i ]- 'a' ]--
9
+ for _ , r := range t {
10
+ frequency [r - 'a' ]--
11
+ }
12
+ for _ , n := range frequency {
13
+ if n != 0 {
14
+ return false
15
+ }
13
16
}
17
+ return true
18
+ }
14
19
15
- for _ , v := range freq {
16
- if v != 0 {
20
+ func isAnagram_unicode (s string , t string ) bool {
21
+ frequency := make (map [rune ]int )
22
+ for _ , r := range s {
23
+ frequency [r ]++
24
+ }
25
+ for _ , r := range t {
26
+ frequency [r ]--
27
+ }
28
+ for _ , n := range frequency {
29
+ if n != 0 {
17
30
return false
18
31
}
19
32
}
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments