fork download
  1. class Solution(object):
  2. def is_palindrome(self, s, left, right):
  3. while left < right:
  4. if s[left] != s[right]:
  5. return False
  6. left += 1
  7. right -= 1
  8. return True
  9.  
  10. def validPalindrome(self, s):
  11. left, right = 0, len(s) - 1
  12.  
  13. while left < right:
  14. if s[left] != s[right]:
  15. return self.is_palindrome(s, left + 1, right) or self.is_palindrome(s, left, right - 1)
  16. left += 1
  17. right -= 1
  18.  
  19. return True
Success #stdin #stdout 0.1s 14184KB
stdin
Standard input is empty
stdout
Standard output is empty