pascals-triangle Java code
2017-10-25 13:16
288 查看
Given numRows, generate the first numRows of Pascal’s triangle.
For example, given numRows = 5,
Return
[
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
]
For example, given numRows = 5,
Return
[
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
]
import java.util.*; public class Solution { public ArrayList<ArrayList<Integer>> generate(int numRows) { ArrayList<ArrayList<Integer>> list = new ArrayList<>(); for (int i = 0; i < numRows; i ++) { ArrayList<Integer> temp = new ArrayList<>(); for (int j = 0; j <= i; j ++) { if(j == 0 || j == i) temp.add(1); else temp.add(list.get(i - 1).get(j - 1) + list.get(i - 1).get(j)); } list.add(temp); } return list; } }
相关文章推荐
- pascals-triangle Java code
- 【LeetCode——JAVA实现】119. pascals-triangle-ii(帕斯卡三角形 II)
- triangle Java code
- Java log code example
- 从一个ConnectionPool的实现看design pattern的运用 (source code for Java 1.1)
- Java was started but returned exit code=13
- LeetCode--pascals-triangle
- Leetcode_pascals-triangle-ii (updated c++ and python version)
- Error:Internal error: (java.io.FileNotFoundException) D:\code\project\.idea\misc.xml (The sys
- Manage, Administrate and Monitor GlassFish v3 from Java code usingAMX & JMX
- binary-tree-maximum-path-sum Java code
- java.io.StreamCorruptedException: invalid type code: AC解决办法
- Leet Code 23 Merge k Sorted Lists - 合并K个有序链表 Java
- 启动eclipse ,出现错误 Java was started but returned exit code=13
- myeclipse 编写java代码提示 dead code 原因
- Google Code Jam Notes - Spaceship Defence - Java
- Leet Code 57 Insert Interval - 插入区间 - Java
- best-time-to-buy-and-sell-stock Java code
- pascals-triangle,pascals-triangle-ii
- Two sample code using javamail