Advertisement
smj007

Untitled

Apr 19th, 2025
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. class Solution:
  2.  
  3.     def validPalindrome(self, s: str) -> bool:
  4.  
  5.         def helper(s: str, left:int, right: int, count: int) -> bool:
  6.             # Base case
  7.             if count > 1:
  8.                 return False
  9.  
  10.             # Base case
  11.             if left >= right:
  12.                 return True
  13.  
  14.             # recursive function
  15.             if s[left] != s[right]:
  16.                 return helper(s, left+1, right, count+1) or helper(s, left, right-1, count+1)
  17.             else:
  18.                 # left += 1
  19.                 # right -= 1
  20.                 return helper(s, left+1, right-1, count)
  21.  
  22.         return helper(s, 0, len(s)-1, 0)
  23.        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement