File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
leetcode/0242.Valid-Anagram Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 1
1
package leetcode
2
2
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
+
3
24
// 解法一
4
25
func isAnagram (s string , t string ) bool {
5
26
alphabet := make ([]int , 26 )
Original file line number Diff line number Diff line change @@ -45,6 +45,21 @@ func Test_Problem242(t *testing.T) {
45
45
para242 {"rat" , "car" },
46
46
ans242 {false },
47
47
},
48
+
49
+ {
50
+ para242 {"a" , "ab" },
51
+ ans242 {false },
52
+ },
53
+
54
+ {
55
+ para242 {"ab" , "a" },
56
+ ans242 {false },
57
+ },
58
+
59
+ {
60
+ para242 {"aa" , "bb" },
61
+ ans242 {false },
62
+ },
48
63
}
49
64
50
65
fmt .Printf ("------------------------Leetcode Problem 242------------------------\n " )
You can’t perform that action at this time.
0 commit comments