题目描述:

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

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

解题思路:

每次在上一个list前面插入1,然后后面的每两个间相加赋值给前一个数。

代码描述:

public class Solution {
public List<Integer> getRow(int rowIndex) {
List<Integer> result = new ArrayList<Integer>();
for(int i = 0; i <= rowIndex; i++){
result.add(0,1);
for(int j = 1; j < i; j++){
result.set(j, result.get(j) + result.get(j + 1));
}
}
return result;
}
}

  

Java [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. Java for 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 ...

  3. 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, ...

  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. C# 数据结构--排序[下]

    希尔排序(Shell Sort) 排序思想: 先取一个小于n的整数d1作为第一个增量,把文件的全部记录分组.所有距离为d1的倍数的记录放在同一个组中.先在各组内进行直接插入排序:然后,取第二个增量d2 ...

  2. 【BZOJ】【2768】【JLOI2010】冠军调查

    网络流/最小割 我不会告诉你这题跟 BZOJ 1934 是一模一样的……包括数据范围…… /****************************************************** ...

  3. input点击删除默认value,以及只能输入数字,删除,tab

    /*inputhastip类绑定事件*/ $('.inputhastip').css("color", "#999"); $('.inputhastip').b ...

  4. unity3d旋转摄像机脚本

    void Update () { )) { if (axes == RotationAxes.MouseXAndY) { // Read the mouse input axis rotationX ...

  5. timeit统计运行时间

    import timeitt1 = timeit.timeit('sum(x*x for x in xrange(10000))',number = 10000) print t1

  6. 【QT】计时器制作

    应小伙伴的要求,做一个小计时器.功能是点击开始就从00:00:00开始计时,点击暂停就暂停计时,点击停止就停止计时. 界面如上图,使用ui设计师直接拖的.按钮和图标的图片都是网上下载的.用美图秀秀抠成 ...

  7. android Notification定义与应用

    首先要明白一个概念: Intent 与 PendingIntent 的区别: Intent:是意图,即告诉系统我要干什么,然后做Intent应该做的事,而intent是消息的内容 PendingInt ...

  8. POJ1008Maya Calendar

    http://poj.org/problem?id=1008&lang=default&change=true 这个题倒是不难,就是麻烦一点,但是还WA了几次都是因为处理天数的时候没处 ...

  9. 【转载】SSH框架总结(将网上朋友写的给整合了下)

    一.Struts 在没有学习SSH框架前,我们一般采用Jsp+javabean+servlet开发,这里就是MVC架构.而Struts其实就是替代了Servlet,我们知道Servlet在一般的开发中 ...

  10. hdu1874 畅通工程续

    http://acm.hdu.edu.cn/showproblem.php?pid=1874 //标准最短路模板 //需要注意的是两点间可能有多组 //需要取最短的 #include<iostr ...