清晰明了
寻找第K大
http://www.nowcoder.com/questionTerminal/e016ad9b7f0b45048c58a9f27ba618bf
import java.util.*; public class Finder { public int findKth(int[] a, int n, int k) { // write code here quicksort(a,0,n-1,n-k); return a[n-k]; } private void quicksort(int[] a, int l,int r, int k) { if (l>=r) return ; int left=l-1; int right=r+1; int mid=a[(left+right)>>1]; while (left<right){ do { left++; } while (a[left]<mid); do { right--; } while (a[right]>mid); if (left<right){ int t=a[left]; a[left]=a[right]; a[right]=t; } } if (right>=k)quicksort(a,l,right,k); else quicksort(a,right+1,r,k); } }