import java.util.LinkedList;
import java.util.List;
/*
* Given numRows, generate the first numRows of Pascal's triangle.
* [
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
]
* */
public class Solution {
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public List<List<Integer>> generate(int numRows) {
// List<Integer> list = new LinkedList<>();
List<List<Integer>> exlist = new LinkedList<>();
for(int i = 0;i<numRows;i++)
{
List<Integer> list = new LinkedList<>();
for(int j = 0;j<=i;j++)
{
//int count = 0;
if(j==0||j==i)
list.add(1);
else{
list.add(exlist.get(i-1).get(j-1)+exlist.get(i-1).get(j));
}
}
exlist.add(list);
}
return exlist;
}
}
Pascal's Triangle
最新推荐文章于 2022-09-08 11:40:48 发布