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. JavaScript设计模式之命令模式

    一.命令模式概念 命令模式(Command)的定义是:用来对方法调用进行参数化处理和传送,经过这样处理过的方法调用可以在任何需要的时候执行.也就是说该模式旨在将函数的调用.请求和操作封装成一个单一的对 ...

  2. 数据库备份工具mysqldump重要参数详解

    1. --single-transaction InnoDB 表在备份时,通常启用选项 --single-transaction 来保证备份的一致性,实际上它的工作原理是设定本次会话的隔离级别为:RE ...

  3. WinPcap编程(前言&&学习)

    计算机网络课设要求用WinPcap写对ARP包的接收与发送. 所以学了一下WinPcap的内容. 参考的博客: http://blog.csdn.net/htttw/article/details/7 ...

  4. sort对二维字符数组排序(转)

    由于二维字符数组的第二维没有赋值运算符,即不能对整个一维数组进行赋值,因此是无法直接对二维数组用sort进行排序的,解决办法有二种: 代码一: #include <iostream> #i ...

  5. SQL Server分区动态生成脚本(三)(按年份划分)

    --生成分区脚本DECLARE @DataBaseName NVARCHAR(50)--数据库名称DECLARE @TableName NVARCHAR(50)--表名称DECLARE @Column ...

  6. get set

    关于C# get set的文章很多,但是笔者的这篇文章有它的特别之处,笔者用简单的语言把c# get set讲述的十分明了. C# get set释一:属性的访问器包含与获取(读取或计算)或设置(写) ...

  7. [Android] hid设备按键流程简述

    hexdump /dev/hidraw0就能看到usbhid设备传输过来的裸流 如:按下Input键 003ae60 0000 0096 8000 006b 0000 0000 0000 0000 * ...

  8. firefox插件poster的使用,发起自定义http请求

    快捷键:ctrl+alt+p 在开发WEB程序的时候,经常需要模拟http请求,接收服务器响应,从而检验程序的正确性. Firefox插件poster,可以模拟各种http请求,并详细设置请求参数,比 ...

  9. COJN 0558 800600带通配符的字符串匹配

    800600带通配符的字符串匹配 难度级别:B: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 通配符是一类键盘字符,当我们不知道真正字符或者 ...

  10. WordPress ‘crypt_private()’方法远程拒绝服务漏洞

    漏洞名称: WordPress ‘crypt_private()’方法远程拒绝服务漏洞 CNNVD编号: CNNVD-201306-250 发布时间: 2013-06-20 更新时间: 2013-06 ...