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];
}