问题描述:
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]
]
import java.util.ArrayList;
import java.util.List;
public class Pascals_Triangle {
public List
> generate(int numRows) {
if(numRows <=0)
return new ArrayList();
List
> result = new ArrayList
>(); for(int i=0; i
list = new ArrayList
(); if(result.size() == 0){ list.add(1); result.add(list); } else{ list.add(1); List
tmplist = result.get(result.size()-1); for(int j = 0; j