寻找第k大
寻找第K大
https://www.nowcoder.com/practice/e016ad9b7f0b45048c58a9f27ba618bf?tpId=196&&tqId=37124&rp=1&ru=/activity/oj&qru=/ta/job-code-total/question-ranking
public int findKth(int[] a, int n, int K) { // write code here return find(a,0,n-1,K); } private int find(int[] a, int start, int end, int k) { if(start==end) return a[start]; int index = partion(a,start,end); int len=a.length; int tar=len-k; if(tar==index) return a[index]; else if(tar<index) return find(a,start,index-1,k); else return find(a,index+1,end,k); } private int partion(int[] a, int start, int end) { int temp=a[start]; int i=start; int j=end; while (i<j){ while (i<j && a[j]>=temp){ j--; } a[i]=a[j]; while (i<j && a[i]<temp){ i++; } a[j]=a[i]; } a[i]=temp; return i; }