Skip to content

Commit 0823979

Browse files
committed
Suggestion for problem 242
1 parent c7d4051 commit 0823979

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

leetcode/0242.Valid-Anagram/242. Valid Anagram.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
package leetcode
22

3+
// suggestion
4+
func isAnagram2(s string, t string) bool {
5+
hash := map[rune]int{}
6+
7+
for _, value := range s {
8+
hash[value]++
9+
}
10+
11+
for _, value := range t {
12+
hash[value]--
13+
}
14+
15+
for _, value := range hash {
16+
if value != 0 {
17+
return false
18+
}
19+
}
20+
21+
return true
22+
}
23+
324
// 解法一
425
func isAnagram(s string, t string) bool {
526
alphabet := make([]int, 26)

0 commit comments

Comments
 (0)