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) extra space?
vector<int> getRow(int rowIndex) {
vector<int> result(1,1);
if(rowIndex==0)return result;
result.push_back(1);
if(rowIndex==1)return result;
int i=2;
while(i!=rowIndex+1)
{
vector<int> tmp(result);
for(int j=1;j<i;j++)
{
result[j]=tmp[j-1]+tmp[j];
}
result.push_back(1);
i++;
}
return result;
}
Pascal's Triangle II的更多相关文章
- 【Leetcode】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 ...
- LeetCode——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 ...
- [LeetCode]Pascal's Triangle II
题目:给定一个行索引index,返回帕斯卡三角形第index层的三角形 算法:生成index层帕斯卡三角形,并返回第index层三角形 public class Solution { public L ...
- Pascal's Triangle I,II
题目来自于Leetcode https://leetcode.com/problems/pascals-triangle/ Given numRows, generate the first numR ...
- leetcode - Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Retu ...
- LeetCode——Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Retu ...
- LeetCode118:Pascal's Triangle
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Retu ...
- 【leetcode】118. Pascal's Triangle
@requires_authorization @author johnsondu @create_time 2015.7.23 19:54 @url [Pascal's Triangle](http ...
- leetcode笔记:Pascal's Triangle
一. 题目描写叙述 Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows ...
随机推荐
- 更改tabBarItem图片的问题
代码: UIImage *normal = [[UIImage imageNamed:@"tabbar_home_default"] imageWithRenderingMode: ...
- Asp.net IsPostBack
Page.IsPostBack是一个标志:当前请求是否第一次打开.调用方法为:Page.IsPostBack或者IsPostBack或者this.IsPostBack或者this.Page.IsPos ...
- 深入理解offsetTop与offsetLeft
做为走上前端不归路的我,以前只是认为offsetTop是元素的左边框至包含元素offsetParent的左内边框之间的像素距离,同理offsetRight是相对于上内边框.那么问题来了,包含元素off ...
- IOS 真机调试以及发布应用 1
参考网站:http://my.oschina.net/u/1245365/blog/196263 Certificates, Identifiers &Profiles 简介 Certif ...
- mysql的limit经典用法及优化
用法一 SELECT `keyword_rank`.* FROM `keyword_rank` WHERE (advertiserid='59') LIMIT 2 OFFSET 1; 比如这个 ...
- Yii框架AR对象数据转化为数组
demo函数作用:将AR对象数据转化为数组 局限:仅用于findAll的多维数组,find一维数组可以先转化为多维数组的一个元素在使用 function actionIndex() { $data = ...
- MySQL的索引
MySQL索引 索引:是一种特殊的文件(InnoDB 数据表上的索引是表空间的一个组成部分),它们包含着对数据表里所有记录的引用指针.其可以加快数据读操作,但会使数据写操作变慢:应该构建在被用作查询条 ...
- MyBatis Generator generatorConfig.xml配置详解
所有Generator的xml详细说明见:http://mybatis.org/generator/configreference/xmlconfig.html (英文版) 引用 http://blo ...
- 台积电16nm工艺为什么好过三星14nm
最近,关于iPhone6s A9处理器版本的事情的话题很热,最后都闹到苹果不得不出来解释的地步,先不评判苹果一再强调的整机综合续航差2~3%的准确性,但是三星14nm工艺相比台积电16nm工艺较差已经 ...
- java中利用RandomAccessFile读取超大文件
超大文件我们使用普通的文件读取方式都很慢很卡,在java中为我提供了RandomAccessFile函数,可以快速的读取超大文件并且不会感觉到卡哦,下面看我的一个演示实例. 服务器的日志文件往往达到4 ...