-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Open
Description
Bug Report for https://neetcode.io/problems/is-anagram
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
I'm running into a weird issue with this problem. The following code works fine for the LeetCode version here: https://leetcode.com/problems/valid-anagram/, but runs into an issue with a "reflect" import that I can't see. I imagine a "reflect" import is being injected unnecessarily for the Go language on this problem?
Edit: I guess it's there because you expect people to use reflect.DeepEqual
to do some kind of comparison between slices, but still I think the below code should run, even if it's sub-optimal.
Language: Go
My code:
func isAnagram(s string, t string) bool {
if len(s) != len(t) {
return false
}
occurrences := make(map[rune]int)
for _, c := range s {
occurrences[c]++
}
for _, c := range t {
if _, ok := occurrences[c]; !ok {
return false
}
occurrences[c]--
}
for _, count := range occurrences {
if count > 0 {
return false
}
}
return true
}
Error message:
# command-line-arguments
./main.go:-4:2: "reflect" imported and not used

Metadata
Metadata
Assignees
Labels
No labels