118. Pascal's Triangle (杨辉三角)
2016-10-27 22:52
281 查看
Given numRows, generate the first numRows of Pascal's triangle.
For example, given numRows = 5,
Return
public class Solution {
public List<List<Integer>> generate(int numRows) {
List<List<Integer>> list = new LinkedList<List<Integer>>();
List<Integer> intList = new LinkedList<Integer>();
for(int i=0;i<numRows;i++){
for(int j=0;j<=i;j++){
if(j==0||j==i)
intList.add(1);
else
intList.add(list.get(i-1).get(j-1)+list.get(i-1).get(j));
}
list.add(intList);
intList = new LinkedList<Integer>();
}return list;
}
}
For example, given numRows = 5,
Return
[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ]
public class Solution {
public List<List<Integer>> generate(int numRows) {
List<List<Integer>> list = new LinkedList<List<Integer>>();
List<Integer> intList = new LinkedList<Integer>();
for(int i=0;i<numRows;i++){
for(int j=0;j<=i;j++){
if(j==0||j==i)
intList.add(1);
else
intList.add(list.get(i-1).get(j-1)+list.get(i-1).get(j));
}
list.add(intList);
intList = new LinkedList<Integer>();
}return list;
}
}
相关文章推荐
- LeetCode-118:Pascal's Triangle (生成指定行数的杨辉三角)
- Leetcode#118. Pascal's Triangle(杨辉三角I)
- [leetCode 118 & 119] Pascal's Triangle I && II (杨辉三角问题)
- 118. Pascal's Triangle 杨辉三角
- Leetcode - Array - 118. Pascal's Triangle(杨辉三角)
- 杨辉三角(Pascal's Triangle)- LeetCode118-119
- (LeetCode)Pascal's Triangle --- 杨辉三角
- Leetcode 119. Pascal's Triangle II 杨辉三角2 解题报告
- 118. Pascal's Triangle (python)
- 118. Pascal's Triangle
- [leetcode, python] Pascal's Triangle II 杨辉三角
- 118. Pascal's Triangle
- LeetCode-118-Pascal's Triangle-E
- 118. Pascal's Triangle
- leetcode 生成杨辉三角形, 118 119 Pascal's Triangle 1,2
- leetcode 118: Pascal's Triangle
- LeetCode 118: Pascal's Triangle
- LeetCode 118 Pascal's Triangle(帕斯卡三角形)(vector)
- 118. Pascal's Triangle
- [C语言][LeetCode][118]Pascal's Triangle