Given a string s, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
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.
Constraints:
1 <= s.length <= 2 * 105s consists only of printable ASCII characters.class Solution {
public:
bool isPalindrome(string s) {
int n = s.size();
int start = 0;
int end = n-1;
while(start<end)
{
while(start<end&&!isalnum(s[start]))
start++;
while(start<end&&!isalnum(s[end]))
end--;
if(tolower(s[start])!=tolower(s[end]))
return false;
start++;
end--;
}
return true;
}
};