cielseven's picture
add 19 shard00 problems, update the algorithms, drop prim_forward_star
3805fe5
Raw History Blame Contribute Delete
282 Bytes
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;
}