add new solutions
This commit is contained in:
parent
886b5e0a8e
commit
67cad91898
47 changed files with 1549 additions and 1 deletions
30
solutions/16/q1657/solution.go
Normal file
30
solutions/16/q1657/solution.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package q1657
|
||||
|
||||
import "slices"
|
||||
|
||||
func closeStrings(word1 string, word2 string) bool {
|
||||
if len(word1) != len(word2) {
|
||||
return false
|
||||
}
|
||||
|
||||
charCount1, charCount2 := make([]int, 26), make([]int, 26)
|
||||
for i := range len(word1) {
|
||||
charCount1[word1[i]-'a']++
|
||||
charCount2[word2[i]-'a']++
|
||||
}
|
||||
|
||||
for i := range charCount1 {
|
||||
if charCount1[i] == 0 && charCount2[i] != 0 {
|
||||
return false
|
||||
}
|
||||
if charCount1[i] != 0 && charCount2[i] == 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
slices.Sort(charCount1)
|
||||
slices.Sort(charCount2)
|
||||
return slices.Equal(charCount1, charCount2)
|
||||
}
|
||||
|
||||
var _ = closeStrings
|
||||
Loading…
Add table
Add a link
Reference in a new issue