mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-25 00:54:46 +01:00
50 lines
633 B
Go
50 lines
633 B
Go
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] {
|
|
if !isEcho(removeIndex(l, s)) && !isEcho(removeIndex(r, s)) {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
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)
|
|
}
|