TOP101题解 | BM47#寻找第K大#
寻找第K大
https://www.nowcoder.com/practice/e016ad9b7f0b45048c58a9f27ba618bf
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
* @author Senky
* @date 2023.08.25
* @par url https://www.nowcoder.com/creation/manager/content/584337070?type=column&status=-1
* @brief 不用去重,使用快排,然后逆序k输出数组元素就是第K大
*
* @param a int整型一维数组
* @param aLen int a数组长度
* @param n int整型
* @param K int整型
* @return int整型
*/
#include <stdlib.h>
int compar(const void* q1, const void* q2)
{
return (*(int*)q1 - *(int*)q2);
}
int findKth(int* a, int aLen, int n, int K )
{
// write code here
qsort(a, aLen, sizeof(a[0]), compar);
return a[aLen - K];
}
#TOP101#TOP101-BM系列 文章被收录于专栏
系列的题解

