Skip to content

Commit

Permalink
go solution for 242 Valid Anagram
Browse files Browse the repository at this point in the history
  • Loading branch information
Damans227 committed Jul 18, 2022
1 parent 5ec20a7 commit f18ca9f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions go/242-Valid-Anagram.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
func isAnagram(s string, t string) bool {

if len(s) != len(t) {
return false
}

s_map := map[rune]int{}
t_map := map[rune]int{}

for _, c := range s {
if _, ok := s_map[c]; !ok {
s_map[c] = 1
} else {
s_map[c] += 1
}
}

for _, c := range t {
if _, ok := t_map[c]; !ok {
t_map[c] = 1
} else {
t_map[c] += 1
}
}

for _, c := range s {
if s_map[c] != t_map[c] {
return false
}
}

return true

}


0 comments on commit f18ca9f

Please sign in to comment.