Given a string s
, return true
if the s
can be palindrome after deleting at most one character from it.
Example 1:
Input: s = "aba"
Output: true
Right point start from 0 and shift to left. Left point start from length-1 and shift to right. Until find different character of right and left point. Check remain string is it a palindrome string, when right point shift to left 1 step or left point shift to right 1 step. I need check two conditions. If both true, return true. Otherwise, return false.
左指針從0開始往右,右指針從length-1開始往左,兩指針向中間前進,直到找到字元不相同的時候。將剩餘的子字串拿出來比對,看看是否在移除1個字元後剩餘的子字串就為相同,有可能是右指針往左,也有可能是左指針需要往右,所以兩個方式都需要判斷,兩者只要其一為true即為true。