A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers.

Given a string s, return true if it is a palindrome, or false otherwise.

&nbsp;
Example 1:

Input: s = "A man, a plan, a canal: Panama"
Output: true
Explanation: "amanaplanacanalpanama" is a palindrome.


Example 2:

Input: s = "race a car"
Output: false
Explanation: "raceacar" is not a palindrome.


Example 3:

Input: s = " "
Output: true
Explanation: s is an empty string "" after removing non-alphanumeric characters.
Since an empty string reads the same forward and backward, it is a palindrome.


&nbsp;
Constraints:


	1 &lt;= s.length &lt;= 2 * 105
	s consists only of printable ASCII characters.


class Solution:
    def isPalindrome(self, s: str) -> bool:
        cleaned = ""
        for c in s:
            if c.isalnum():
                cleaned += c.lower()
        return (cleaned == cleaned[::-1])

            
class Solution {
    public boolean isPalindrome(String s) {
        if(s.length()==1 || s.length()==0)
        {
            return true;
        }

        s=s.trim().toLowerCase();
        //s=s.toLowerCase();
        String a="";
        boolean bool=false;
        for(int i=0;i<s.length();i++)
        {
            if((s.charAt(i)>='a' && s.charAt(i)<='z') || (s.charAt(i)>='0' && s.charAt(i)<='9'))
            {
                a=a+s.charAt(i);
            }
        }
        if(a.length()==1 || a.length()==0)
        {
            return true;
        }
        for(int i=0;i<a.length()/2;i++)
        {
            if(a.charAt(i)==a.charAt(a.length()-i-1))
            {
                bool=true;
            }
            else{
                return false;
            }
        }

        return bool;
    }
}
class Solution {
public:
    bool isPalindrome(string s) {
        auto it = remove_if(s.begin(), s.end(), [](char const &c) {
            return !isalnum(c);
        });

        s.erase(it, s.end());
        transform(s.begin(), s.end(), s.begin(), ::tolower);

        int i = 0;
        int j = s.size()-1;

        while(i <= j) {
            if(s[i] != s[j]) return false;
            i++; j--;
        }

        return true;
    }
};
var isPalindrome = function(s) {
  const toLower = s.toLowerCase().replace(/[\W_\s]+/g, '').replace(/ /g, '')
  let m = 0
  let n = toLower.length - 1

  while (m < n) {
    if (toLower[m] !== toLower[n]) {
      return false
    }
    m++
    n--
  }
  return true
}
Valid Palindrome