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. 01 javaSe 01 抽象类和接口

      抽象类 接口   目录(?)[-] 1 抽象类与接口是面向对象思想层面概念不是程序设计语言层面概念 2 抽象类是本体的抽象接口是行为的抽象 3 C中抽象类与接口的探讨     目录(?)[+]   ...

  2. Hadoop的IO操作

    Hadoop的API官网:http://hadoop.apache.org/common/docs/current/api/index.html   相关的包 org.apache.hadoop.io ...

  3. beego——模型定义

    复杂的模型定义不是必须的,此功能用作数据库数据转换和自动建表 默认的表名规则,使用驼峰转蛇形: AuthUser -> auth_user Auth_User -> auth__user ...

  4. TRegExpr正则表达式

    TRegExpr正则表达式 2006-10-24 10:55 DELPHi中的REGEXPR   [ 2006-03-29 11:33:46 am | Author: Admin ] 其实这个Pasc ...

  5. delphi webbrowser post自动登录

    delphi webbrowser post自动登录     var  EncodedDataString: WideString;  PostData: OleVariant;  Headers: ...

  6. Redis整合Spring实现缓存

    一.Redis介绍 什么是Redis? redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set( ...

  7. Hadoop2.7.x中所有的DataNode都启动不了解决办法

    参考:Hadoop集群所有的DataNode都启动不了解决办法说明现象:我自己出现这个问题的原因是:自己在namenode格式化之后创建了一些文件,然后重新执行了namenode格式化导致的. 现象就 ...

  8. NAT配置与管理

    为解决IPv4地址日益枯竭,出现NAT(Network Address Translation,网络地址转换)技术.NAT可以将来自一个网络的IP数据报报头中的IP地址(可以是源IP地址或目的IP地址 ...

  9. 20165101刘天野 2018-2019-2《网络对抗技术》Exp1 逆向与Bof基础

    20165101刘天野 2018-2019-2<网络对抗技术>Exp1 逆向与Bof基础 1. 逆向及Bof基础实践说明 1.1 实践目标 本次实践的对象是一个名为pwn1的linux可执 ...

  10. Win32 API编程:显示系统进程列表

    #include <windows.h> #include <tlhelp32.h> // 声明快照函数的头文件 #include "tchar.h" #i ...