20201201: fix bug

This commit is contained in:
VicRen
2020-12-01 09:17:52 +08:00
parent ea0f41aa12
commit c93930c737
2 changed files with 12 additions and 4 deletions

View File

@@ -10,7 +10,7 @@ func isEcho(s string) bool {
} }
l := 0 l := 0
r := len(s) - 1 r := len(s) - 1
for r >= l { for r > l {
if s[l] != s[r] { if s[l] != s[r] {
return false return false
} }
@@ -26,9 +26,12 @@ func isAlmostEcho(s string) bool {
} }
l := 0 l := 0
r := len(s) - 1 r := len(s) - 1
for r >= l { for r > l {
if s[l] != s[r] && !isEcho(removeIndex(l, s)) && !isEcho(removeIndex(r, s)) { if s[l] != s[r] {
return false if !isEcho(removeIndex(l, s)) && !isEcho(removeIndex(r, s)) {
return false
}
return true
} }
l++ l++
r-- r--

View File

@@ -75,6 +75,11 @@ func Test_isAlmostEcho(t *testing.T) {
args{"abcbba"}, args{"abcbba"},
true, true,
}, },
{
"test6",
args{"abcdcbba"},
true,
},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {