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>> pascalTriangle = new ArrayList<List<Integer>>(); List<Integer> currLevel = new ArrayList<Integer>(); currLevel.add(1); while(numRows>0){ pascalTriangle.add(new ArrayList<Integer>(currLevel)); currLevel = generateNextLevel(currLevel); numRows--; } return pascalTriangle; } public List<Integer> generateNextLevel(List<Integer> currLevel){ List<Integer> nextLevel = new ArrayList<Integer>(); if(currLevel.size()!=0){ currLevel.add(0); currLevel.add(0,0); for(int runner=0; runner<currLevel.size()-1; runner++){ nextLevel.add(currLevel.get(runner)+currLevel.get(runner+1)); } } return nextLevel; } }

Note: for each row, pretend there is always one 0 at each side of the row. So the triangle would look like following, so when calculating next level, just need to sum each adjacent integers in the current level.

[ 0[1]0, 0[1,1]0, 0[1,2,1]0, 0[1,3,3,1]0, 0[1,4,6,4,1]0 ]