题目:

题解:
int majorityElement(int* nums, int numsSize) {
    int ans = 0;
    for (int i = 0, cnts = 0; i < numsSize; i++) {
        if (nums[i] == ans) {
            cnts++;
        } else if (cnts == 0) {
            ans = nums[i];
        } else {
            cnts--;
        }
    }
    return ans;
}
                


















