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?

Hide Tags

Array

  1. vector<int> getRow(int rowIndex) {
  2. vector<int> result(1,1);
  3. if(rowIndex==0)return result;
  4. result.push_back(1);
  5. if(rowIndex==1)return result;
  6. int i=2;
  7. while(i!=rowIndex+1)
  8. {
  9. vector<int> tmp(result);
  10. for(int j=1;j<i;j++)
  11. {
  12. result[j]=tmp[j-1]+tmp[j];
  13. }
  14. result.push_back(1);
  15. i++;
  16. }
  17. return result;
  18. }

Pascal&#39;s Triangle II的更多相关文章

  1. 【Leetcode】Pascal&#39;s Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3 ...

  2. LeetCode——Pascal&#39;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. [LeetCode]Pascal&#39;s Triangle II

    题目:给定一个行索引index,返回帕斯卡三角形第index层的三角形 算法:生成index层帕斯卡三角形,并返回第index层三角形 public class Solution { public L ...

  4. Pascal&#39;s Triangle I,II

    题目来自于Leetcode https://leetcode.com/problems/pascals-triangle/ Given numRows, generate the first numR ...

  5. leetcode - Pascal&#39;s Triangle

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Retu ...

  6. LeetCode——Pascal&#39;s Triangle

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Retu ...

  7. LeetCode118:Pascal&#39;s Triangle

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Retu ...

  8. 【leetcode】118. Pascal&#39;s Triangle

    @requires_authorization @author johnsondu @create_time 2015.7.23 19:54 @url [Pascal's Triangle](http ...

  9. leetcode笔记:Pascal&#39;s Triangle

    一. 题目描写叙述 Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows ...

随机推荐

  1. Oracle 创建分页存储过程(转帖)

    原贴地址:http://19880614.blog.51cto.com/4202939/1316560 ps:源代码还有很多错误,我修改了 ------------------------------ ...

  2. 使用top工具,找出消耗CPU 较多的进程

    1.使用top工具,找出消耗CPU 较多的进程 [oracle@cuug ~]$ top top - 10:48:27 up 23:15,  4 users,  load average: 1.09, ...

  3. js 实现win7任务栏拖动效果

    前言 在某个时刻, 我认识了一个朋友. 此人在我的教唆下, 踏上了js的不归路. 前天他问我, Win7任务栏拖动效果怎么实现. 我随口就跟他说, 这简单的一逼. 在我一晚上的折腾之后, 一份潦草的代 ...

  4. underscorejs-map学习

    2.2 map 2.2.1 语法: _.map(list, iteratee, [context]) 2.2.2 说明: 对集合的每个成员依次进行某种操作,将返回的值依次存入一个新的数组.接收3个参数 ...

  5. 使用Ajax.ActionLink时,点击对应的按钮会重新加载一个页面,而不是在当前页面的指定模块加载

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. bzoj1188: [HNOI2007]分裂游戏

    Description 聪聪和睿睿最近迷上了一款叫做分裂的游戏. 该游戏的规则试: 共有 n 个瓶子, 标号为 0,1,2.....n-1, 第 i 个瓶子中装有 p[i]颗巧克力豆,两个人轮流取豆子 ...

  7. codevs 1017 乘积最大

    1017 乘积最大 2000年NOIP全国联赛普及组NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描 ...

  8. 多台web服务器之间共享session

    常见的几种方法如下: 1. 写客户端Cookie的方式 当用户登陆成功以后,把网站域名.用户名.密码.token.session有效时间全部采用cookie的形式写入到客户端的cookie里面,如果用 ...

  9. 测试和恢复性的争论:面向对象vs.函数式编程

    Michael Feathers最近的博文在博客社区引发了一场异常激烈的论战.Feathers发表言论说一些面向对象编程语言的内嵌特性有助于测试的进行,并且使用面向对象编程语言编写的代码更容易恢复. ...

  10. spring restful 中文乱码问题

    进行如下配置: @RequestMapping( value="/zzs/xgm", produces="application/json;charset=utf-8&q ...