From ee407374b0ab01c8dfb82875c2a4d4ac62a096cd Mon Sep 17 00:00:00 2001 From: dwyaneini Date: Wed, 10 Jun 2015 17:29:40 +0800 Subject: [PATCH] Update 01.04.md In the previous code, due to using s[first] and s[second], the program will be crashed with the error "Array subscript is not an integer". Both of "first" and "second" are a pointer to a char. --- ebook/zh/01.04.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ebook/zh/01.04.md b/ebook/zh/01.04.md index 6b48e5424..0c6961ad6 100644 --- a/ebook/zh/01.04.md +++ b/ebook/zh/01.04.md @@ -59,8 +59,12 @@ bool IsPalindrome2(const char *s, int n) second = s + n - 1 - m; while (first >= s) - if (s[first--] != s[second++]) - return false; // not equal, so it's not apalindrome + { + if (*first != *second) + return false; // not equal, so it's not apalindrome + first--; + second++; + } return true; // check over, it's a palindrome } ```