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