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)
{
ArrayList<List<Integer>> l=new ArrayList<List<Integer>>();
int n=0;
int[] a=new int[numRows];
while(n<numRows)
{
LinkedList<Integer> list=new LinkedList<Integer>();
for(int i=n-1;i>=0;i--)
{
if(i==0)
{
list.addFirst(1);
continue;
}
a[i]=a[i-1]+a[i];
list.add(a[i]);
}
list.add(1);
a[n]=1;
l.add(list);
n++;
}
return l;
}
}