# [Valid Palindrome](https://leetcode.com/problems/valid-palindrome/) ###### tags: `Leetcode`, `Easy`, `Two Pointers` ## Approach * Initialize two pointers `left` and `right` to the `0` and `len(nums) - 1` respectively * Check if char at left and char at right is alphanumeric * if char at left is equal to char at right then increment left and decrement right by 1 each * else return False * If char at left is not alphanumeric then increment left * If char at right is not alphanumeric then decrement right * Return True ## Asymptotic Analysis ### Time Complexity: **O(N)** ### Space Complexity: **O(1)** ## Code ``` python class ValidPalindrome: @staticmethod def is_palindrome(s: str) -> bool: left, right = 0, len(s) - 1 while left < right: if s[left].isalnum() and s[right].isalnum(): if s[left].lower() == s[right].lower(): left += 1 right -= 1 else: return False elif not s[left].isalnum(): left += 1 elif not s[right].isalnum(): right -= 1 return True s = "A man, a plan, a canal: Panama" print(ValidPalindrome.is_palindrome(s)) ```