Skip to content

Latest commit

 

History

History
31 lines (22 loc) · 524 Bytes

680.md

File metadata and controls

31 lines (22 loc) · 524 Bytes

680 Valid Palindrome II

Description

link


Solution

  • See Code

Code

O(n)

class Solution:
    def validPalindrome(self, s: str) -> bool:
        l, r = 0, len(s) - 1
        while l < r:
            if s[l] != s[r]:
                pre, las = s[l:r], s[l + 1:r + 1]
                return pre[::-1] == pre or las[::-1] == las
            else:
                l += 1
                r -= 1
        return True