leetcode:119. Pascal's Triangle II(Java)解答

原创 2016年01月10日 17:52:58

转载请注明出处:z_zhaojun的博客
原文地址:http://blog.csdn.net/u012975705/article/details/50493006
题目地址:https://leetcode.com/problems/pascals-triangle-ii/

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,1].

解法(Java):

public class Solution {
    public List<Integer> getRow(int rowIndex) {
        if (rowIndex < 0) {
            return null;
        }
        rowIndex++;
        List<Integer> list = new ArrayList<>();
        list.add(1);
        for (int row = 0; row < rowIndex; row++) {
            int tmp = 1;
            for (int col = 1; col <= row; col++) {
                if (col < list.size()) {
                    int tmp2 = list.get(col);
                    list.set(col, tmp + list.get(col));
                    tmp = tmp2;
                } else {
                    list.add(1);
                }
            }
        }
        return list;
    }
}
版权声明:本文为博主原创文章,转载请注明出处。博客首页:http://blog.csdn.net/u012975705。订阅:http://blog.csdn.net/u012975705/rss/list

LeetCode118 LeetCode119 LeetCode151 LeetCode202 Java

LeetCode 118   static public List> generate(int numRows) { List> res = new ArrayLi...

【LeetCode-面试算法经典-Java实现】【119-Pascal's Triangle II(帕斯卡三角形(杨辉三角)II)】

【119-Pascal’s Triangle II(帕斯卡三角形II)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题  Given an index k, return t...

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

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

LeetCode: Pascal's Triangle II [119]

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

【leetcode】119. Pascal's Triangle II

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

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

LeetCode119 Pascal's Triangle II

详细见:leetcode.com/problems/pascals-triangle-ii Java Solution: github package leetcode; impor...
  • zxwtry
  • zxwtry
  • 2017年05月04日 22:23
  • 220

118、119 pascal's triangle I、II---Array-LeetCode

118 pascal's triangle I---Array-LeetCode 找规律 a = b + c。 119 pascal's triangle II---Array-LeetCode ...

LeetCode - 119. Pascal's Triangle II

这道题目与118. Pascal's Triangle很像,所不同的是这道题要求的是打印出制定某行,而上一题则是将所有的全都打印出来。一个非常简单的想法自然是先计算出整个三角形,然后再打印出某个指定的...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:leetcode:119. Pascal's Triangle II(Java)解答
举报原因:
原因补充:

(最多只允许输入30个字)