Given numRows, generate the first numRows of Pascal's triangle.
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>> res = new ArrayList<List<Integer>>();
if (numRows == 0) {
return res;
}
for (int i = 0; i < numRows; i++) {
ArrayList<Integer> arrayList = new ArrayList<Integer>();
arrayList.add(1);
for (int j = 1; j < i; j++) {
List<Integer> list = res.get(i-1);
int tmp = list.get(j-1) + list.get(j);
arrayList.add(tmp);
}
if (i != 0) {
arrayList.add(1);
}
res.add(arrayList);
}
return res;
}
}