传送门 有一个整数数组,请你根据快速排序的思路,找出数组中第K大的数。 给定一个整数数组a,同时给定它的大小n和要找的K(K在1到n之间),请返回第K大的数,保证答案存在。 测试样例: note: 注意手写快排的时候: leetcode: 传送门 215. Kth Largest Element i ...
分类:
其他好文 时间:
2016-08-01 19:13:01
阅读次数:
195
首先复习一下quicksort. 先理解partition函数,就是选序列的最后一个数作为pivot,比它小的排到它左边,比它大的在它右边,它在中间。但是它左右的部分并没有排序。 返回值是这个pivot所在的位置,pivot所在位置就是它最终的位置,也就是说比如index是5,说明它就是第6大的数。 ...
分类:
其他好文 时间:
2016-07-24 07:01:32
阅读次数:
86
Find the kth smallest number in at row and column sorted matrix. Find the kth smallest number in at row and column sorted matrix. Find the kth smalles ...
分类:
其他好文 时间:
2016-07-14 07:10:27
阅读次数:
165
目录
一.dfs序在树状图中的经典应用
二.初探双向广度优先搜索
三.整体二分思想完美解决kth number问题
四.实战模拟退火思想(变步长贪心算法)
五.凸包问题经典例题
六.树的重心问题经典例题
七.矩阵快速幂例题
一.dfs序在树状图中的经典应用
首先是dfs序的问题,什么是dfs序?...
分类:
其他好文 时间:
2016-07-10 18:51:01
阅读次数:
295
Problem: https://leetcode.com/problems/kth-largest-element-in-an-array/ Find the kth largest element in an unsorted array. Note that it is the kth lar ...
分类:
其他好文 时间:
2016-07-09 19:16:14
阅读次数:
184
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3,3,1]. Note:Could you optimize your algorithm to us ...
分类:
编程语言 时间:
2016-07-06 11:39:40
阅读次数:
151
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For exam ...
分类:
编程语言 时间:
2016-07-04 17:07:45
阅读次数:
140
题目: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3,3,1]. 链接: http://leetcode.com/problems/pascals ...
分类:
其他好文 时间:
2016-06-24 10:49:01
阅读次数:
149
Given two integer arrays sorted in ascending order and an integer k. Define sum = a + b, where a is an element from the first array and b is an elemen ...
分类:
其他好文 时间:
2016-06-21 20:47:29
阅读次数:
277
Find the kth smallest number in at row and column sorted matrix. Given k = 4 and a matrix: [ [1 ,5 ,7], [3 ,7 ,8], [4 ,8 ,9], ] return 5 这一题是Kth Large ...
分类:
其他好文 时间:
2016-06-21 17:07:38
阅读次数:
327