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. java内存相关

    (类是对象的抽象,而对象是类的具体实例.类是抽象的,不占用内存,而对象是具体的,占用存储空间.) 1.java是如何管理内存的 java的内存管理就是对象的分配和释放问题.(其中包括两部分) 分配:内 ...

  2. servlet中获取各种相对地址(服务器、服务器所在本地磁盘、src等)。

    [本文简介] 本文将提供javaWeb中经常使用到的相对路径的获取方法,分别有: url基本地址 带目录的url地址 服务器的根路径 服务器所在的 本地磁盘路径 服务器所在的本地磁盘路径,带文件夹 S ...

  3. Android图片加载框架Picasso最全使用教程5

    在之前的四篇博客中,我们学习了所有的关于Picasso的主要方法,我们也对这个Picasso有了一个很深的认识,下面就主要对Picasso自身进行分析,这样的话,会让我们更了解Picasso的核心方法 ...

  4. 收藏一些好用的c语言数据结构

    14.redis内置的链表,非常好 adlist.c /* adlist.c - A generic doubly linked list implementation * * Copyright ( ...

  5. VK Cup 2018 - Round 1+Codeforces Round #470

    A. Primal Sport 题意:有两个人轮流玩游戏.给出数X(i-1),轮到的人需要找到一个小于X(i-1)的素数x,然后得到Xi,Xi是x的倍数中大于等于X(i-1)的最小的数.现在已知X2, ...

  6. react下将输入的汉字转化为拼音

    1.首先需要一个简单的拼音和汉字对应的字典文件: /** * 收录常用汉字6763个,不支持声调,支持多音字,并按照汉字使用频率由低到高排序 */ var pinyin_dict_notone = { ...

  7. Cookie应用参考

    内容来自imooc.

  8. 【Head First Servlets and JSP】笔记23:Expression Language(EL) 完全攻略

    基本上是<Head First Servlets and JSP>内容的整理.扩充.顺便推荐一个供参考的JSP教程:JSP Tutorial内容很全面,还有一些有趣的实例. 完整代码参考 ...

  9. 2018年Java面试题搜集

    2018年Java面试题搜集 一.Servlet执行流程(浏览器访问servlet的过程容器) 客户端发起http请求,web服务器将请求发送到servlet容器,servlet容器解析url并根据w ...

  10. Vim:gvim安装配置(windows)

    Vim:gvim安装配置(windows) 一.gvim的特点: vim要求全部键盘操作,而gvim可以使用鼠标进行可视化操作,即gvim是vim的图形化界面: 二.gvim安装: 下载地址:http ...