Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.
For example,"A man, a plan, a canal: Panama"
is a palindrome."race a car"
is not a palindrome.
class Solution { public: bool isPalindrome(string s) { int sSize = s.size(); int i=0,j=sSize-1; int diff = 'a'-'A'; while(i<j){ while((i<j) && !((s[i]>='a' && s[i]<='z') || (s[i]>='A' && s[i]<='Z') || (s[i]>='0' && s[i]<='9'))){i++;} while((i<j) && !((s[j]>='a' && s[j]<='z') || (s[j]>='A' && s[j]<='Z') || (s[j]>='0' && s[j]<='9'))){j--;} if(i>=j){ return true; } if(s[i]==s[j] || s[i]==s[j]+diff || s[j] == s[i]+diff){ i++; j--; }else{ return false; } } return true; } };