Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3,3,1].解题思路:注意,本题的k相当于上题的k+1,其他照搬即可,JAVA实现如下: pub...
分类:
编程语言 时间:
2015-05-24 17:21:09
阅读次数:
174
class Solution {public: int findKthLargest(vector& nums, int k) { int index=0; int backindex = nums.size()-1, forindex = 0; while(1)...
分类:
其他好文 时间:
2015-05-24 16:58:15
阅读次数:
145
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 example,
Given [3,2,1,5,6,4] and k = 2, return 5.
...
分类:
其他好文 时间:
2015-05-23 18:25:13
阅读次数:
131
https://leetcode.com/problems/kth-largest-element-in-an-array/Kth Largest Element in an ArrayFind thekth largest element in an unsorted array. Note th...
分类:
其他好文 时间:
2015-05-23 18:21:33
阅读次数:
106
Find thekth largest element in an unsorted array.For example,Given[3,2,1,5,6,4]and k = 2, return 5.Note:You may assume k is always valid, 1 ≤ k ≤ arra...
分类:
其他好文 时间:
2015-05-23 12:50:52
阅读次数:
134
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 use only O(k) extra space?
从后往前计算
//用一个数组滚...
分类:
其他好文 时间:
2015-05-19 22:39:04
阅读次数:
151
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 use only O(k) extra space?
基本思路:
内层循环,使用...
分类:
其他好文 时间:
2015-05-17 16:51:36
阅读次数:
111
Pascal's Triangle II
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 use only O(k) ex...
分类:
其他好文 时间:
2015-05-12 15:45:55
阅读次数:
143
分析:可以用线段树做,但感觉麻烦。用优先队列,每次插入时都保留前k个大的数即可。
#include
#include
#include
using namespace std;
int main()
{
int n,k,j,c;
char b[2];
ios::sync_with_stdio(false);
while(cin>>n>>k)
{
priority_queue,g...
分类:
其他好文 时间:
2015-05-10 15:49:40
阅读次数:
118
problem:
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 use only O(k) extra spac...
分类:
其他好文 时间:
2015-04-24 12:40:14
阅读次数:
151