Check if the string is a palindrome with one allowed deletion. When a mismatch occurs, try removing either side.
Here's the solution:
function validPalindrome(s):
left = 0
right = s.length - 1
while left < right:
if s[left] != s[right]:
return isPalin(s, left+1, right) or isPalin(s, left, right-1)
left += 1
right -= 1
return true
function isPalin(s, lo, hi):
while lo < hi:
if s[lo] != s[hi]:
return false
lo += 1
hi -= 1
return true
time, space.