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

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

解题思路:

注意,本题的k相当于上题的k+1,其他照搬即可,JAVA实现如下:

    public List<Integer> getRow(int rowIndex) {
List<Integer> alist=new ArrayList<Integer>();
rowIndex++;
if(rowIndex<=0)
return alist;
alist.add(1);
for(int i=2;i<=rowIndex;i++){
List<Integer> alist2=new ArrayList<Integer>();
alist2.add(1);
for(int j=1;j<i-1;j++){
alist2.add(alist.get(j-1)+alist.get(j));
}
alist2.add(1);
alist=alist2;
}
return alist;
}

Java for LeetCode 119 Pascal's Triangle II的更多相关文章

  1. [LeetCode] 119. Pascal's Triangle II 杨辉三角 II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  2. leetcode 119 Pascal's Triangle II ----- java

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  3. Java [Leetcode 119]Pascal's Triangle II

    题目描述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return ...

  4. LeetCode 119. Pascal's Triangle II (杨辉三角之二)

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  5. [LeetCode] 119. Pascal's Triangle II 杨辉三角之二

    Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note t ...

  6. LeetCode 119 Pascal's Triangle II

    Problem: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Ret ...

  7. C#解leetcode:119. Pascal's Triangle II

    题目是: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return  ...

  8. Leetcode 119 Pascal's Triangle II 数论递推

    杨辉三角,这次要输出第rowIndex行 用滚动数组t进行递推 t[(i+1)%2][j] = t[i%2][j] + t[i%2][j - 1]; class Solution { public: ...

  9. LeetCode OJ 119. Pascal's Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

随机推荐

  1. Define Custom Data Filter Using Pre-Query Trigger In Oracle Forms

    Oracle Forms is having its default records filter, which we can use through Enter Query mode to spec ...

  2. Oracle 检查表空间使用情况

    --检查表空间使用情况  SELECT f.tablespace_name       , a.total "total (M)"       , f.free "fre ...

  3. StringUtils和IOUtils工具包的使用

    加载apache的工具类 <dependency> <groupId>commons-lang</groupId> <artifactId>common ...

  4. 性能测试脚本开发(C&C#&Java)

    一.C语言实现及相关问题解决 LR:C函数-功能描述 LR:C函数-适用范围 LR:C函数-头信息传递 LR:C函数-字符串编码转换 lr_convert_string_encoding(" ...

  5. Spring boot Security Disable security

    When I use security.basic.enabled=false to disable security on a Spring Boot project that has the fo ...

  6. 微信小程序-获取用户信息(getUserInfo)

    当小程序抹杀掉这个接口的时候,多少人心凉了.. 作为一个初级web前端开发,我是更加懵逼,小程序员跑路了... 当时以及现在用的办法就是: 1.增加一个登陆或授权页 2.上线以后自动获取 3.增加一个 ...

  7. android图片素材參考

    hpi:通常是大图像素是:480x800   (640*960)宽比长大致为0.6左右      一般240dpi.    小图的像素依据实际来. xhdi:一般大图像素是: 640x1136 (72 ...

  8. Shell脚本值:运算符

    算术运算符 原生bash不支持简单的数学运算,但是可以通过其他命令来实现,例如 awk 和 expr,expr 最常用. expr 是一款表达式计算工具,使用它能完成表达式的求值操作. 例如:实现两个 ...

  9. 算法 Heap sort

    // ------------------------------------------------------------------------------------------------- ...

  10. 【转载】ASP.NET之旅--深入浅出解读IIS架构

    在学习Asp.net时,发现大多数作者都是站在一个比较高的层次上讲解Asp.Net. 他们耐心. 细致地告诉你如何一步步拖放控件. 设置控件属性.编写 CodeBehind代码,以实现某个特定的功能. ...