Skip to content

Commit e59bc06

Browse files
committed
valid_anagram
1 parent 60cf4cc commit e59bc06

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ Golang solution for leetcode. For each problem, there is a simple *_test.go to t
197197
#### [239. Sliding Window Maximum](https://github.com/hitzzc/go-leetcode/tree/master/sliding_window_maximum)
198198
#### [240. Search a 2D Matrix II](https://github.com/hitzzc/go-leetcode/tree/master/search_a_2D_matrix_II)
199199
#### [241. Different Ways to Add Parentheses](https://github.com/hitzzc/go-leetcode/tree/master/different_ways_to_add_parentheses)
200+
#### [242. Valid Anagram](https://github.com/hitzzc/go-leetcode/tree/master/valid_anagram)
200201

201202

202203

valid_anagram/valid_anagram.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package valid_anagram
2+
3+
import (
4+
"sort"
5+
)
6+
7+
func isAnagram(s string, t string) bool {
8+
if len(s) != len(t) {
9+
return false
10+
}
11+
m := [26]int{}
12+
for i := range s {
13+
m[int(s[i]-'a')]++
14+
m[int(t[i]-'a')]--
15+
}
16+
for i := range m {
17+
if m[i] != 0 {
18+
return false
19+
}
20+
}
21+
return true
22+
}

0 commit comments

Comments
 (0)