Given numRows, generate the first numRows of Pascal's triangle.
For example, given numRows = 5,
public class Solution {
public ArrayList<ArrayList<Integer>> generate(int numRows) {
ArrayList<ArrayList<Integer>> lists = new ArrayList<ArrayList<Integer>>();
if(numRows == 0) return lists;
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(1);
lists.add(list);
if(numRows == 1) return lists;
ArrayList<Integer> pre = list;
for(int i = 2; i <= numRows; i++){
list = new ArrayList<Integer>();
list.add(1);
for(int j = 1; j < i - 1; j++){
list.add(pre.get(j - 1) + pre.get(j));
}
list.add(1);
pre = list;
lists.add(list);
}
return lists;
}
}