自学内容网 自学内容网

C语言 | Leetcode C语言题解之第414题第三大的数

题目:

题解:

int cmp(const void *a, const void *b) {
    return *(int*)a < *(int*)b;
}

int thirdMax(int* nums, int numsSize){
    qsort(nums, numsSize, sizeof(nums[0]), cmp);
    int diff = 0;
    for (int i = 1; i < numsSize; i++) {
        if (nums[i] != nums[i - 1] && ++diff == 2) {
            return nums[i];
        }
    }
    return nums[0];
}

原文地址:https://blog.csdn.net/m0_59237910/article/details/142322347

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!