Solution 1Two Pointer

class Solution:
    def isPalindrome(self, s: str) -> bool:
        s = s.lower()
        left = 0
        right = len(s)-1
        while left < len(s)-1 and not s[left].isalnum():
            left += 1
        while right > 0 and not s[right].isalnum():
            right -= 1
        while left < right:
            if s[left] != s[right]: return False
            left += 1
            right -= 1
            while left < len(s)-1 and not s[left].isalnum():
                left += 1
            while right > 0 and not s[right].isalnum():
                right -= 1
        return True
Leet Code/python.py · L324–342
public boolean isAlNum(char c) {
    return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'); 
}
public boolean isPalindrome(String s) {
    s = s.toLowerCase();
    int left = 0, right = s.length()-1;
    while (left < right) {
        while ( !isAlNum(s.charAt(left)) && left < right ) {
            left++;
        }
        while ( !isAlNum(s.charAt(right)) && right > left ) {
            right--;
        }
        if ( s.charAt(left) != s.charAt(right) ) {
            return false;
        }
        left++;
        right--;
    }
    return true;
}
Leet Code/java.java · L320–341

Solution 2Regex Reverse

Python
class Solution:
    def isPalindrome(self, s: str) -> bool:
        s = re.sub(r'[^a-z0-9]+', '', s.lower())
        return s == s[::-1]
Leet Code/python.py · L343–347

Solution 3Filter Reverse

Python
class Solution:
    def isPalindrome(self, s: str) -> bool:
        s = [ch for ch in s.lower() if ch.isalnum()]
        return s == list(reversed(s))
Leet Code/python.py · L348–352

Solution 4Half Compare

Python
class Solution:
    def isPalindrome(self, s: str) -> bool:
        s = ''.join([ch for ch in s.lower() if ch.isalnum()])
        return s[:len(s)//2] == s[-1:-(len(s)//2)-1:-1]
Leet Code/python.py · L353–357