Problem List

Valid Anagram

May 29, 2025Go hashmap, stringeasy

Problem

Approach

Edge Cases

Reflections

Go doesn't have a built-in counter or defaultdict like Python, so I had to roll my own hash map. Not a big deal, but worth noting. Felt like a pretty clean solution overall.

Performance

Complexity

Go Solution
func isAnagram(s string, t string) bool {
  if len(s) != len(t) {
    return false
  }

  m := make(map[rune]int)
  for _, letter := range s {
    m[letter]++
  }

  for _, letter := range t {
    m[letter]--
    if m[letter] < 0 {
      return false
    }
  }

  return true
}
LeetCode Problem Link