问题来源:http://www.careercup.com/question?id=6335704 问题描述: Given a N*N Matrix. All rows are sorted, and all columns are sorted. Find the Kth Largest element of the matrix. 解答: 先给出算法的时空复杂度,时间O(k * lg k),空间O(k). 算法:为了方便描述不防假设矩阵左上角的元素最小,且k<=n. 1. 取每行行首元素建…
求一组N个数中的第k个最大者,设k=N/2. import java.util.Random; public class K_Max { /** * @param args */ //求第K大的数,保证K大于等于1,小于等于array.length/2哦 public static int TopK(int array[],int K) { int topk[] = new int [K]; for(int i = 0; i<topk.length;i++) topk[i] = array[i]…