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. 在pycharm中导入PyMysql出错,解决方法

    在写Django项目的时候,需要用到数据库中的数据,我们在pycharm中需导入  import PyMySQL; 如果没有该模块会报错,像我这样: 如果你的错误像我这样,那么你按照我的方法应该能搞好 ...

  2. Delphi 正则表达式之TPerlRegEx 类的属性与方法(7): Split 函数

    Delphi 正则表达式之TPerlRegEx 类的属性与方法(7): Split 函数 //字符串分割: Split var   reg: TPerlRegEx;   List: TStrings; ...

  3. Delphi 正则表达式之TPerlRegEx 类的属性与方法(4): Replace

    Delphi 正则表达式之TPerlRegEx 类的属性与方法(4): Replace // Replace var   reg: TPerlRegEx; begin   reg := TPerlRe ...

  4. C#转义字符(好记性不如烂笔头)

    C#转义字符: ·一种特殊的字符常量:·以反斜线"\"开头,后跟一个或几个字符.·具有特定的含义,不同于字符原有的意义,故称“转义”字符.·主要用来表示那些用一般字符不便于表示的控 ...

  5. CodeForces - 919D Substring (拓扑排序+dp)

    题意:将一个字符串上的n个字符视作点,给出m条有向边,求图中路径上最长出现的相同字母数. 分析:首先如果这张图中有环,则可以取无限大的字符数,在求拓扑排序的同时可以确定是否存在环. 之后在拓扑排序的结 ...

  6. asp.net MVC 强类型视图表单Ajax提交的注意事项

    xmfdsh这几天遇到这么一个问题,在MVC中通过model模型生成的强类型视图的表单,在提交后的回调函数并没有发挥作用.如下图: 如上图,无论是通过Ajax.BeginForm或者Html.Begi ...

  7. 关于Webpage Not Found问题解决~~~

    还是外文网站好,以下解决办法: IIS6.0 UI vs. IIS 7.x UI Series: More about Web Service Extensions This week in the ...

  8. Linux 进程管理 kill、killall、pkill命令

    Linux常用信号(进程间通信) 系统中可以识别的信号较多,我们可以使用命令"kill -l"或"man 7 signal"来查询.命令如下: [root@lo ...

  9. Linux命令(6/28)——declare/typeset命令

    declare 与 typeset 命令是bash的内建命令,两者是完全一样的,用来声明shell变量,设置变量的属性. declare命令(别名typeset)属shell内建命令,用于申明shel ...

  10. 【WIN7】windows\system32 下的几乎所有文件的简单说明【2】

    1: System32的详解 C:\WINDOWS\system32... 2:   3: 这个 system32 文件夹中包含了大量的用于 Windows 的文件. 这里主要用于存储 DLL 文件, ...