题解 | #寻找第K大#
寻找第K大
http://www.nowcoder.com/practice/e016ad9b7f0b45048c58a9f27ba618bf
int findKth(int* a, int aLen, int n, int K ) {
// write code here
int max, temp;//最大值和下标
int i,j;
for(j=0; j<K; j++)
{
max = 0;
for(i=1; i<n-j; i++)
{
if(a[max] < a[i])
max = i;
}
temp = a[max];
a[max] = a[i-1];
a[i-1] = temp;
//printf("%d\n",temp);
}
return temp;
}
查看18道真题和解析