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 ArrayList<ArrayList<Integer>> generate(int numRows) {
ArrayList<ArrayList<Integer>> res = new ArrayList<ArrayList<Integer>>();
if(numRows <= 0) return res;
ArrayList<Integer> preList = new ArrayList<Integer>();
preList.add(1);
res.add(preList);
for(int i=1; i<numRows; i++){
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(1);
for(int j=1; j<i; j++){
int t = preList.get(j-1) + preList.get(j);
list.add(t);
}
list.add(1);
res.add(list);
preList = list;
}
return res;
}
}