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>> result = new ArrayList<List<Integer>>();
Integer[] rowArray = {};
for(int i = 0; i < numRows; i++){
Integer[] tempArray = new Integer[i+1];
tempArray[0] = 1;
tempArray[tempArray.length - 1] = 1;
for(int j = 1; j < i; j++){
tempArray[j] = rowArray[j-1] + rowArray[j];
}
rowArray = tempArray;
result.add(Arrays.asList(rowArray));
}
return result;
}
}