This commit is contained in:
VicRen
2020-12-01 08:47:46 +08:00
parent 508e8c9c08
commit ea0f41aa12
2 changed files with 167 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
package main
func main() {
}
func isEcho(s string) bool {
if s == "" {
return false
}
l := 0
r := len(s) - 1
for r >= l {
if s[l] != s[r] {
return false
}
l++
r--
}
return true
}
func isAlmostEcho(s string) bool {
if s == "" {
return false
}
l := 0
r := len(s) - 1
for r >= l {
if s[l] != s[r] && !isEcho(removeIndex(l, s)) && !isEcho(removeIndex(r, s)) {
return false
}
l++
r--
}
return true
}
func removeIndex(index int, s string) string {
if index >= len(s) {
return s
}
ret := []rune(s)
ret = append(ret[0:index], ret[index+1:]...)
return string(ret)
}