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

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&#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. 浅谈C++ Lambda 表达式(简称LB)

    C++ 11 对LB的支持,对于喜欢Functional Programming的人来说,无疑是超好消息.它使得C++进入了和C#,JavaScript等现代流行的程序设计语言所代表的名人堂. 不熟悉 ...

  2. 二十分钟弄懂C++11 的 rvalue reference (C++ 性能剖析 (5))

    C++ 11加了许多新的功能.其中对C++性能和我们设计class的constructor或assignment可能产生重大影响的非rvalue reference莫属!我看了不少资料,能说清它的不多 ...

  3. 在IE6/7/8下识别html5标签

    识别html5标签: html5添加了许多语义化的标签,比如<nav></nav>,<aside></aside>,<article>< ...

  4. CLR via C#可空值类型

    我们知道,一个值类型的变量永远不可能为null.它总是包含值类型本身.遗憾的是,这在某些情况下会成为问题.例如,设计一个数据库时,可将一个列定义成为一个32位的整数,并映射到FCL的Int32数据类型 ...

  5. [异常解决] Make nRF51 DFU Project Appear "fatal error: uECC.h: No such file or directory"

    What's the problem When I make the nRF51's DFU project appear "no uECC.h" error: And then ...

  6. UI基础 - UIScrollView

    scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(, , , )]; scrollView.backgroundColor = [ ...

  7. 从零开始学Sketch——进阶篇-b

    从零开始学Sketch——进阶篇 Sketch是一款矢量绘图应用,而矢量绘图无疑是目前进行网页.图标以及界面设计的最好方式. 在初识了Sketch的界面布局和基础工具之后,我们就可以开始进入高阶的Sk ...

  8. SANS top 20

    What Are the Controls?The detailed Consensus Audit Guidelines are posted at http://www.sans.org/cag/ ...

  9. poj 2516Minimum Cost

    http://poj.org/problem?id=2516 #include<cstdio> #include<cstring> #include<algorithm& ...

  10. 不用预计算切向空间的Normal mapping

    先贴出shader 吧 等有时间了 来阐述原理 // vertex shader //varying vec3 ViewPosition; //varying vec3 Normal; varying ...