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