Simplest cpp code


#1

int Solution::solve(string A) {
int n=A.length();
int lo=0,hi=n-1;int flag=0;
while(lo<hi){
if(A[lo]!=A[hi]){
if(flag)return 0;
flag++;
if(A[lo+1]==A[hi]) lo++;
else if(A[hi-1]==A[lo])hi–;
else return 0;
}
lo++;hi–;
}
return 1;

}


#2

Plz Run for “abcdcbab”
the given code returns 0
but should give 1