C++, by Moore Voting Algo, you can definitely tell me how to Improvise


#1
int Solution::majorityElement(const vector<int> &A) 
{
    int major = A[0];
    int count = 1;
    for(int i=1;i<A.size();i++)
    {
        if(major == A[i])
            count++;
        else
            count--;
        
        if(count == 0)
        {
            major = A[i];
            count = 1;
        }
    }
    
    return major;
}