Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def validPalindrome(self, s: str) -> bool:
- def helper(s: str, left:int, right: int, count: int) -> bool:
- # Base case
- if count > 1:
- return False
- # Base case
- if left >= right:
- return True
- # recursive function
- if s[left] != s[right]:
- return helper(s, left+1, right, count+1) or helper(s, left, right-1, count+1)
- else:
- # left += 1
- # right -= 1
- return helper(s, left+1, right-1, count)
- return helper(s, 0, len(s)-1, 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement