Faaez Razeen

Valid Palindrome

  • 1 min read
  • String
  • LC-Easy

3 years ago

Solution

TimeSpaceExplanation
O(n)O(1)
def isPalindrome(self, s: str) -> bool: l, r = 0, len(s) - 1 while l < r: while l < r and not s[l].isalnum(): l += 1 while r > l and not s[r].isalnum(): r -= 1 if s[l].lower() != s[r].lower(): return False l += 1 r -= 1 return True