Very Basic C++ solution


#1

int Solution::solve(vector &A) {
int n=A.size(),i,j;
if(n==0)
return 0;
vectorbe(n,0),bo(n,0),ae(n,0),ao(n,0);
int f=0;
for(i=1;i<n;i++)
{
if(f==0)
be[i]=be[i-1]+A[i-1];
else
be[i]=be[i-1];
if(f==1)
bo[i]=bo[i-1]+A[i-1];
else
bo[i]=bo[i-1];
f=!f;
}
if(n%2!=0)
f=0;
else
f=1;
for(i=n-2;i>=0;i–)
{
if(f==0)
ae[i]=ae[i+1]+A[i+1];
else
ae[i]=ae[i+1];
if(f==1)
ao[i]=ao[i+1]+A[i+1];
else
ao[i]=ao[i+1];
f=!f;
}
int ans=0;
for(i=0;i<n;i++)
{
if(be[i]+ao[i]==bo[i]+ae[i])
ans++;
}
return ans;
}