题目链接:https://leetcode-cn.com/problems/pascals-triangle/
题目如下:
class Solution {
public List<List<Integer>> generate(int numRows) {
//List<List<Integer>> sumlist=new ArrayList<Integer>();// 会报错
List<List<Integer>> sumlist = new ArrayList<>();//留意写法,先写大list, 不报错
int[][] array=new int[numRows][numRows];
for(int i=0;i<numRows;i++){
List<Integer> sublist=new ArrayList<Integer>();//写小list,依次写完之后放入大list
for(int j=0;j<=i;j++){
if(j==0||i==j) array[i][j]=1;
else array[i][j]=array[i-1][j-1]+array[i-1][j];
sublist.add(array[i][j]);
}
sumlist.add(sublist);
}
return sumlist;
}
}