Given numRows, generate the first numRows
For example, given numRows = 5,
Return
[
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
]
题意:打印杨辉三角形
思路:用list辅助存储,写得很水
import java.util.ArrayList;
public class Solution {
public List<List<Integer>> generate(int numRows) {
List<List<Integer>> resultList = new ArrayList<List<Integer>>();
if(numRows == 0) {
return resultList;
}
List<Integer> list = new ArrayList<Integer>();
list.add(1);
resultList.add(list);
for(int i = 1; i < numRows; i++) {
List<Integer> temp = resultList.get(i - 1);
list = new ArrayList<Integer>();
list.add(1);
for(int j = 1; j <= i - 1; j++) {
int m = temp.get(j - 1) + temp.get(j);
list.add(m);
}
list.add(1);
resultList.add(list);
}
return