Given an index k, return the kth row of the Pascal's triangle.

For example, given k = 3,
Return [1,3,3,1].

还是帕斯卡三角,只不过这里指定的是某一个特定的层,然后直接返回,这个就可以使用从后往前更新数组的方法,其实I也可以用这个方法来做的,只不过当时没想到啊,代码如下:

 class Solution {
public:
vector<int> getRow(int rowIndex) {
vector<int> ret;
ret.resize(rowIndex + );
ret[] = ;
for(int i = ; i <= rowIndex; ++i){
for(int j = i; j > ; --j){
if(j == i)
ret[j] = ;
else
ret[j] = ret[j] + ret[j - ];
}
}
return ret;
}
};

LeetCode OJ:Pascal's TriangleII(帕斯卡三角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 OJ——Pascal's Triangle II

    http://oj.leetcode.com/problems/pascals-triangle-ii/ 杨辉三角2,比杨辉三角要求的空间上限制Could you optimize your algo ...

  3. [Leetcode][JAVA] Pascal's Triangle I, II

    Pascal's Triangle: Given numRows, generate the first numRows of Pascal's triangle. For example, give ...

  4. 【LeetCode OJ】Linked List Cycle II

    Problem link: http://oj.leetcode.com/problems/linked-list-cycle-ii/ The solution has two step: Detec ...

  5. LeetCode OJ——Unique Binary Search Trees II

    http://oj.leetcode.com/problems/unique-binary-search-trees-ii/ 一题要求得出所有树的种类数,二题要求得出所有树. 在一题的基础上修改代码, ...

  6. LeetCode OJ——Pascal's Triangle

    http://oj.leetcode.com/problems/pascals-triangle/ 杨辉三角 先分析数据,找出规律 ans[row][col] = ans[row-1][col-1]+ ...

  7. 【leetcode】Pascal's Triangle I & II (middle)

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

  8. LeetCode OJ 142. Linked List Cycle II

    Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note ...

  9. LeetCode OJ 92. Reverse Linked List II

    Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...

  10. LeetCode OJ:Linked List Cycle II(循环链表II)

    Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note ...

随机推荐

  1. git rm与直接rm的区别

    git rm 行为: 1.删除一个文件 2.将被删除的这个文件纳入缓存区 $ git rm a rm 'a' $ git status On branch master Changes to be c ...

  2. Python3+Selenium3自动化测试-(三)

    selenium键盘事件 #coding=utf-8 from selenium import webdriver import time from selenium.webdriver.common ...

  3. 用仿ActionScript的语法来编写html5——第三篇,鼠标事件与游戏人物移动

    第三篇,鼠标事件与游戏人物移动 一,假设假设,所有可添加鼠标事件的对象,都有一个mouseEvent方法,添加的鼠标事件同过这个mouseEvent来调用.这样的话,添加鼠标事件,其实只需要给canv ...

  4. 最全的sublime插件整理

    Package Control 插件管理器 1)在Sublime中打开View –> Show Console,将以下代码复制到输入框中后按回车键 import urllib.request,o ...

  5. POJ1276:Cash Machine(多重背包)

    题目:http://poj.org/problem?id=1276 多重背包模板题,没什么好说的,但是必须利用二进制的思想来求,否则会超时,二进制的思想在之前的博客了有介绍,在这里就不多说了. #in ...

  6. pandas(五)处理缺失数据和层次化索引

    pandas用浮点值Nan表示浮点和非浮点数组中的缺失数据.它只是一个便于被检测的标记而已. >>> string_data = Series(['aardvark','artich ...

  7. jupyter常用快捷键

    Jupyter Notebook 有两种键盘输入模式.即命令模式和编辑模式,这与 vim有些类似. 在编辑模式下,可以往单元中键入代码或文本,此时单元格被绿色的框线包围,且命令模式下的快捷键不生效. ...

  8. oracle ORA-01704: string literal too long

    导出数据时,在SQL拼接处,提示 oracle ORA-01704: string literal too long sql:  WITH already_in AS (SELECT distinct ...

  9. 一个用于实现并行执行的 Java actor 库

    即使 Java 6 和 Java 7 中引入并发性更新,Java 语言仍然无法让并行编程变得特别容易.Java 线程.synchronized 代码块.wait/notify 和java.util.c ...

  10. ES6 Promise 让异步函数顺序执行

    应用 ES6 的 内置对象 Promise, 让异步函数 按顺序执行的例子 如下: 上边 是四个用Promise 处理过的 异步执行的函数: fn1.fn2.fn3.fn4 下面,让其按顺序执行 如下 ...