Skip to content

Instantly share code, notes, and snippets.

@Desolve
Created May 3, 2020 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Desolve/5e6a346fd0f59d8135ef0d84b4abff17 to your computer and use it in GitHub Desktop.
Save Desolve/5e6a346fd0f59d8135ef0d84b4abff17 to your computer and use it in GitHub Desktop.
0680 Valid Palindrome II
class Solution:
def validPalindrome(self, s: str) -> bool:
def isp(s: str, l: int, r: int) -> bool:
while l < r:
if s[l] != s[r]: return False
l, r = l + 1, r - 1
return True
i, j = 0, len(s) - 1
while i < j:
if s[i] != s[j]: return isp(s, i + 1, j) or isp(s, i, j - 1)
i, j = i + 1, j - 1
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment