Skip to content

Commit

Permalink
add sol
Browse files Browse the repository at this point in the history
  • Loading branch information
ductnn committed Feb 5, 2025
1 parent 4372832 commit 3988358
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions leetcode/daily/1790/sol.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package main

import "fmt"

func areAlmostEqual(s1 string, s2 string) bool {
if s1 == s2 {
return true
}

var diff []int
for i := 0; i < len(s1); i++ {
if s1[i] != s2[i] {
diff = append(diff, i)
}
}

if len(diff) != 2 {
return false
}

i, j := diff[0], diff[1]
return s1[i] == s2[j] && s1[j] == s2[i]
}

func main() {
s1 := "bank"
s2 := "kanb"

fmt.Print(areAlmostEqual(s1, s2))
}

0 comments on commit 3988358

Please sign in to comment.