From c93930c737650a7718b89216bce023bfd0620462 Mon Sep 17 00:00:00 2001 From: VicRen Date: Tue, 1 Dec 2020 09:17:52 +0800 Subject: [PATCH] 20201201: fix bug --- 20201201/main.go | 11 +++++++---- 20201201/main_test.go | 5 +++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/20201201/main.go b/20201201/main.go index 789394e..d360851 100644 --- a/20201201/main.go +++ b/20201201/main.go @@ -10,7 +10,7 @@ func isEcho(s string) bool { } l := 0 r := len(s) - 1 - for r >= l { + for r > l { if s[l] != s[r] { return false } @@ -26,9 +26,12 @@ func isAlmostEcho(s string) bool { } l := 0 r := len(s) - 1 - for r >= l { - if s[l] != s[r] && !isEcho(removeIndex(l, s)) && !isEcho(removeIndex(r, s)) { - return false + for r > l { + if s[l] != s[r] { + if !isEcho(removeIndex(l, s)) && !isEcho(removeIndex(r, s)) { + return false + } + return true } l++ r-- diff --git a/20201201/main_test.go b/20201201/main_test.go index 51a055b..d70d64d 100644 --- a/20201201/main_test.go +++ b/20201201/main_test.go @@ -75,6 +75,11 @@ func Test_isAlmostEcho(t *testing.T) { args{"abcbba"}, true, }, + { + "test6", + args{"abcdcbba"}, + true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {