Skip to content

Commit a23afe7

Browse files
authored
Merge pull request #1770 from SamTheKorean/main
[SAM] WEEK 2 Solutions
2 parents ae891a0 + bb110c5 commit a23afe7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

valid-anagram/SamTheKorean.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// TC : O(n) : it iterates for the length of nums
2+
// SC : O(n) : we make hashmap as the size of the given string
3+
func isAnagram(s string, t string) bool {
4+
if len(s) != len(t) {
5+
return false
6+
}
7+
8+
letterCounts := make(map[rune]int)
9+
10+
for _, ch := range s {
11+
letterCounts[ch]++
12+
}
13+
14+
for _, ch := range t {
15+
letterCounts[ch]--
16+
if letterCounts[ch] < 0 {
17+
return false
18+
}
19+
}
20+
21+
return true
22+
}

0 commit comments

Comments
 (0)