You are viewing a single comment's thread. Return to all comments →
def palindromeIndex(s): def is_palindrome(s, left, right): while left < right: if s[left] != s[right]: return False left += 1 right -= 1 return True left, right = 0, len(s) - 1 while left < right: if s[left] != s[right]: if is_palindrome(s, left + 1, right): return left elif is_palindrome(s, left, right - 1): return right else: return -1 left += 1 right -= 1 return -1
Seems like cookies are disabled on this browser, please enable them to open this website
Palindrome Index
You are viewing a single comment's thread. Return to all comments →