Solution in O(n) One Pass in C++


#1

Hope you like the solution!!!
int Solution::majorityElement(const vector &nums) {
int count = 0;
int candidate = -1;`

    for (int num : nums) {
    if (count == 0) candidate = num;
        count += (num == candidate) ? 1 : -1;
    }
    return candidate;
 }