Easy to understand: C++ O(n) Solution


#1

int Solution::isPalindrome(string A) {
int i=0;
int j=A.size()-1;
while(i<=j){
if(A[i]>=‘A’ && A[i]<=‘Z’){
A[i]+=32;
}
if(A[j]>=‘A’ && A[j]<=‘Z’){
A[j]+=32;
}
if((A[i]<‘a’ || A[i]>‘z’) && (A[i]<‘0’ || A[i]>‘9’)){
i++;
continue;
}
if((A[j]<‘a’ || A[j]>‘z’) && (A[j]<‘0’ || A[j]>‘9’)){
j–;
continue;
}
if(A[i]!=A[j]){
return 0;
}
if(A[i]==A[j]){
i++;
j–;
continue;
}
}
return 1;
}