From 6dd1be9cd0778751344f32d0e09a05993f08c0a5 Mon Sep 17 00:00:00 2001 From: ductnn Date: Sun, 10 Dec 2023 18:52:48 +0700 Subject: [PATCH] add sol --- .../determineIfTwoStringsAreClose.go | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 leetcode/leetcode75/1657.DetermineIfTwoStringsAreClose/determineIfTwoStringsAreClose.go diff --git a/leetcode/leetcode75/1657.DetermineIfTwoStringsAreClose/determineIfTwoStringsAreClose.go b/leetcode/leetcode75/1657.DetermineIfTwoStringsAreClose/determineIfTwoStringsAreClose.go new file mode 100644 index 0000000..9e08a00 --- /dev/null +++ b/leetcode/leetcode75/1657.DetermineIfTwoStringsAreClose/determineIfTwoStringsAreClose.go @@ -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)) +}