File size: 282 Bytes
bff4ec7
 
 
 
 
3805fe5
bff4ec7
 
 
 
 
 
 
3805fe5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int majorityElement(int* nums, int numsSize)

{
    int vote = 0;
    int candidate = 0;
    
    for (int i = 0; i < numsSize; i++) {
        if (vote == 0) {
            candidate = nums[i];
        }
        vote += (nums[i] == candidate) ? 1 : -1;
    }
    return candidate;
}