Skip to content

Commit 9588803

Browse files
authored
add: valid-anagram solution in go (#43)
1 parent b3a2b2f commit 9588803

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ LeetCode
214214
|0239|[Sliding Window Maximum](https://leetcode.com/problems/sliding-window-maximum/) || [c++](./src/0239-Sliding-Window-Maximum/0239.cpp) |[python](./src/0239-Sliding-Window-Maximum/0239.py)|||||Medium|
215215
|0240|[Search a 2D Matrix II](https://leetcode.com/problems/search-a-2d-matrix-ii/) || [c++](./src/0240-Search-a-2D-Matrix-II/0240.cpp) |[python](./src/0240-Search-a-2D-Matrix-II/0240.py)|||||Medium|
216216
|0241|[Different Ways to Add Parentheses](https://leetcode.com/problems/different-ways-to-add-parentheses/) || [c++](./src/0241-Different-Ways-to-Add-Parentheses/0241.cpp) |[python](./src/0241-Different-Ways-to-Add-Parentheses/0241.py)|||||Medium|
217-
|0242|[Valid Anagram](https://leetcode.com/problems/valid-anagram/) || [c++](./src/0242-Valid-Anagram/0242.cpp) |[python](./src/0242-Valid-Anagram/0242.py)|||||Easy|
217+
|0242|[Valid Anagram](https://leetcode.com/problems/valid-anagram/) || [c++](./src/0242-Valid-Anagram/0242.cpp) |[python](./src/0242-Valid-Anagram/0242.py)|[go](./src/0242-Valid-Anagram/0242.go)||||Easy|
218218
|0242|[Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths/) || [c++](./src/0257-Binary-Tree-Paths/0257.cpp) |[python](./src/0257-Binary-Tree-Paths/0257.py)|||||Easy|
219219
|0253|[Meeting Rooms II](https://leetcode.com/meeting-rooms-ii) || [c++](./src/0253-Meeting-Rooms-II/0253.cpp) |[python](./src/0253-Meeting-Rooms-II/0253.py)|||||Medium|
220220
|0260|[Single Number III](https://leetcode.com/problems/single-number-iii/) || [c++](./src/0260-Single-Number-III/0260.cpp) |[python](./src/0260-Single-Number-III/0260.py)|||[java](./src/0260-Single-Number-III/0260.java)||Medium|

src/0242-Valid-Anagram/0242.go

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package validanagram
2+
3+
func isAnagram(s string, t string) bool {
4+
if len(s) != len(t) {
5+
return false
6+
}
7+
mp := make(map[rune]int, 0)
8+
for _, v := range s {
9+
mp[v]++
10+
}
11+
for _, v := range t {
12+
mp[v]--
13+
if mp[v] < 0 {
14+
return false
15+
}
16+
}
17+
return true
18+
}

0 commit comments

Comments
 (0)