Easy 11 lines C++ Solution : Time - O(N) Space- O(1)


#1
int Solution::solve(vector<int> &A) {
    int odd_l=0,odd_r=0,even_l=0,even_r=0;
    int count=0,n=A.size();
    for(int i=0;i<n;i++)odd_r+=(i%2)?A[i]:0,even_r+=(!(i%2))?A[i]:0;
    for(int i=0;i<n;i++){
        if(i%2)odd_r-=A[i];
        else even_r-=A[i];
        if(odd_l+even_r==odd_r+even_l)count++;
        odd_l+=(i%2)?A[i]:0;
        even_l+=(!(i%2))?A[i]:0;
    }
    return count;
}