How is this solution in cpp wrong?


#1

int Solution::solve(vector &A) {
int n=(int)A.size();
if(n<=1){
return n;
}
if(n==2){
return 0;
}
vector sum_right(n,0);
sum_right[n-1]=A[n-1];
sum_right[n-2]=A[n-2];
for(int i=n-3;i>=0;i–){
sum_right[i]=A[i]+sum_right[i+2];
}
int count=0;
int oi=sum_right[0];
int ii=sum_right[1];
for(int i=0;i<n;i++){
int tmp_oi, tmp_ii;
if(i%2==0){
tmp_oi=oi-sum_right[i]+sum_right[i+1];
tmp_ii=ii-sum_right[i+1]+sum_right[i+2];
}else{
tmp_ii=ii-sum_right[i]+sum_right[i+1];
tmp_oi=oi-sum_right[i+1]+sum_right[i+2];
}

    if(tmp_oi==tmp_ii){
        count++;
    }
}
return count;

}