Created
May 3, 2020 10:32
-
-
Save Desolve/5e6a346fd0f59d8135ef0d84b4abff17 to your computer and use it in GitHub Desktop.
0680 Valid Palindrome II
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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