题解 | #寻找第K大#
寻找第K大
https://www.nowcoder.com/practice/e016ad9b7f0b45048c58a9f27ba618bf
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param a int整型一维数组
* @param aLen int a数组长度
* @param n int整型
* @param K int整型
* @return int整型
*/
int findKth(int* a, int aLen, int n, int K ) {
// write code here
unsigned long k_max;
int pos = 0;
while(--K >= 0)
{
k_max = 0;
// 循环找到最大值
while(--aLen >= 0)
{
if(k_max < a[aLen])
{
pos = aLen;
k_max = a[aLen];
}
}
// 将数组中的最大值置零
a[pos] = 0;
aLen = n;
}
return k_max;
}
