Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Dec 10, 2023
1 parent 4dbb50f commit 6dd1be9
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"fmt"
"sort"

"slices"
)

func closeStrings(word1 string, word2 string) bool {
map1 := make([]int, 26)
map2 := make([]int, 26)
for _, c := range word1 {
map1[c-'a']++
}
for _, c := range word2 {
map2[c-'a']++
}
if !slices.EqualFunc(map1, map2, func(v1, v2 int) bool { return (v1 == 0) == (v2 == 0) }) {
return false
}
sort.Ints(map1)
sort.Ints(map2)
return slices.Equal(map1, map2)
}

func main() {
word1 := "uau"
word2 := "ssx"

fmt.Println(closeStrings(word1, word2))
}

0 comments on commit 6dd1be9

Please sign in to comment.