Valid Palindrome
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.
function IsPalindromeValid(string) {
let left = 0
let right = string.length - 1;
while (left < right) {
if (string[left] === ' ') {
left++;
continue;
} else if (string[right] === ' ') {
right--;
continue;
}
if (string[left] !== string[right]) {
return false
}
left++;
right--;
}
return true;
}
Input: s = "A man, a plan, a canal: Panama"
Output: true
Explanation: "amanaplanacanalpanama" is a palindrome.
Input: s = "race a car"
Output: false
Explanation: "raceacar" is not a palindrome.