mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-30 07:28:41 +01:00
20201201
This commit is contained in:
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user