mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
366 B
24 lines
366 B
![]()
4 years ago
|
package solutions
|
||
|
|
||
|
func IsAnagram(s, t string) bool {
|
||
|
alph := make([]int, 26)
|
||
|
for i := 0; i < len(s); i++ {
|
||
|
if s[i] < 'a' || s[i] > 'z' {
|
||
|
continue
|
||
|
}
|
||
|
alph[s[i]-'a']++
|
||
|
}
|
||
|
for i := 0; i < len(t); i++ {
|
||
|
if t[i] < 'a' || t[i] > 'z' {
|
||
|
continue
|
||
|
}
|
||
|
alph[t[i]-'a']--
|
||
|
}
|
||
|
for i := 0; i < 26; i++ {
|
||
|
if alph[i] != 0 {
|
||
|
return false
|
||
|
}
|
||
|
}
|
||
|
return true
|
||
|
}
|