Description:

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

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

public class Solution {
public List<Integer> getRow(int rowIndex) {
List<List<Integer>> list = new ArrayList<List<Integer>>();
for(int i=0; i<=rowIndex; i++) {
List<Integer> tList = new ArrayList<Integer>();
if(i == 0) {
tList.add(1);
}
else {
for(int j=0; j<=i; j++) {
if(j == 0 || j == i) {
tList.add(1);
}
else {
tList.add(list.get(i-1).get(j) + list.get(i-1).get(j-1));
}
}
}
list.add(tList);
}
return list.get(rowIndex); }
}

LeetCode——Pascal's Triangle II的更多相关文章

  1. 学会从后往前遍历,例 [LeetCode] Pascal's Triangle II,剑指Offer 题4

    当我们需要改变数组的值时,如果从前往后遍历,有时会带来很多麻烦,比如需要插入值,导致数组平移,或者新的值覆盖了旧有的值,但旧有的值依然需要被使用.这种情况下,有时仅仅改变一下数组的遍历方向,就会避免这 ...

  2. LeetCode: Pascal's Triangle II 解题报告

    Pascal's Triangle II Total Accepted: 19384 Total Submissions: 63446 My Submissions Question Solution ...

  3. [LeetCode] 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, ...

  4. [leetcode]Pascal's Triangle II @ Python

    原题地址:https://oj.leetcode.com/problems/pascals-triangle-ii/ 题意: Given an index k, return the kth row ...

  5. LeetCode - Pascal's Triangle II

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

  6. LeetCode Pascal's Triangle II (杨辉三角)

    题意:给出杨辉三角的层数k,返回最后一层.k=0时就是只有一个数字1. 思路:滚动数组计算前一半出来,返回时再复制另一半.简单但是每一句都挺长的. 0ms的版本: class Solution { p ...

  7. leetcode:Pascal's Triangle II【Python版】

    1.将tri初始化为[1],当rowIndex=0时,return的结果是:1,而题目要求应该是:[1],故将tri初始化为[[1]],返回结果设置为tri[0]即可满足要求: 2.最开始第二层循环是 ...

  8. LeetCode:Pascal's Triangle I II

    LeetCode:Pascal's Triangle Given numRows, generate the first numRows of Pascal's triangle. For examp ...

  9. leetcode 118. Pascal's Triangle 、119. Pascal's Triangle II 、120. Triangle

    118. Pascal's Triangle 第一种解法:比较麻烦 https://leetcode.com/problems/pascals-triangle/discuss/166279/cpp- ...

随机推荐

  1. Android—— Intent参数this问题

    Android Intent参数this问题 (2013-04-02 11:19:48) 转载▼ 标签: android intent 分类: Android 转自:http://blog.csdn. ...

  2. zoj3228 Searching the String AC自动机查询目标串中模式串出现次数(分可覆盖,不可覆盖两种情况)

    /** 题目:zoj3228 Searching the String 链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=34 ...

  3. 关于BETA、RC、ALPHA、Release、GA等版本号的意义

    关于BETA.RC.ALPHA.Release.GA等版本号的意义 转载 2016年06月19日 00:04:00 2049 0 1 . 最近由于工作需要经常要去SVN上拉开源项目的源码,对项目 ...

  4. jquery-easyui 中表格的行编辑功能

    具体实现代码如下: <table id="tt"></table> $('#tt').datagrid({ title:'Editable DataGrid ...

  5. Error -27740: WSA_IO_pending

    Error -27740: WSA_IO_pendingAction.c(198): Error -27791: Server **** has shut down the connection pr ...

  6. msysgit使用方法

    安装好后运行"Git Bash",出现命令框. 输入 ssh-keygen -t rsa -C “your_email@youremail.com” 会提示SSH Public K ...

  7. openfire数据库mysql配置

    <?php return array( //'配置项'=>'配置值' //'USERNAME'=>'admin', //赋值 //数据库配置信息 'DB_TYPE' => 'm ...

  8. Android isUserAMonkey()

    Monkey是Android上的一个自动化测试工具.产生随机事件由于压力测试等. ActivityManager.isUserAMonkey()判断当前是否有运行的Monkey测试.有就返回true. ...

  9. e656. 创建基本图形

    Shape line = new Line2D.Float(x1, y1, x2, y2); Shape arc = new Arc2D.Float(x, y, w, h, start, extent ...

  10. e554. 在浏览器状态栏中显示信息

    // See also e551 精简的Applet applet.showStatus("Your Message Here"); Related Examples