-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
leetcode/leetcode75/1657.DetermineIfTwoStringsAreClose/determineIfTwoStringsAreClose.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |