Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Dec 16, 2023
1 parent 2bc4f9c commit 2ffe6a5
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions leetcode/242.ValidAnagram/validAnagram.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package main

import (
"fmt"
)

func isAnagram(s string, t string) bool {
if len(s) != len(t) {
return false
}
cnt := [26]int{}
for i := 0; i < len(s); i++ {
cnt[s[i]-'a']++
cnt[t[i]-'a']--
}
for _, v := range cnt {
if v != 0 {
return false
}
}
return true
}

func main() {
s := "anagram"
t := "nagaram"
fmt.Println(isAnagram(s, t))
}

0 comments on commit 2ffe6a5

Please sign in to comment.