题目要求:
Given numRows, generate the first numRows of `
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) {
int[][] arr = new int[numRows][numRows];
for(int i = 0; i < numRows; i++) {
for(int j = 0; j <= i; j++) {
if(j == 0 || j == i) arr[i][j] = 1;
else arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j];
}
}
List<List<Integer>> list = new ArrayList<List<Integer>>();
for(int i = 0; i < arr.length; i++) {
List<Integer> listx = new ArrayList<Integer>();
for(int index : arr[i]) {
if(index != 0) listx.add(index);
}
list.add(listx);
}
return list;
}
}