최대 1 분 소요

Python

class Solution:
    def validPalindrome(self, s: str) -> bool:
        left, right = 0, len(s) - 1
        while left < right:
            if(s[left] != s[right]):
                return self.Palindrome(s, left + 1, right) or self.Palindrome(s, left, right - 1)
            left, right = left + 1, right -1
        
        return True
    
    def Palindrome(self, s, left, right):
        while left < right:
            if(s[left] != s[right]):
                return False
            left, right = left + 1, right -1
        
        return True

댓글남기기