Anybody plz tell why it is not giving correct answer


#1

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


#2

I don’t know y u r using abs and all…convert the string to either lower case or upper case and then just compare characters from beginning and end.


#3

if(A[i]==A[j] || abs(A[i]-A[j])==abs(‘a’-‘A’)){}
this line evalutes to true even for 9 and Y or 8 and X or where ever ASCII difference is 32.


#4

if you have already figured it out then cool, otherwise try the test case “aa:” and you might get the error in your code