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]]
1 public class Solution { 2 public ArrayList> generate(int numRows) { 3 ArrayList > result = new ArrayList >(); 4 List item; 5 if (numRows <= 0) return result; 6 for (int i=0; i (); 8 for (int j=0; j<=i; j++) { 9 if (j==0 || j==i) item.add(1);10 else {11 List prev = result.get(i-1);12 item.add(prev.get(j-1) + prev.get(j));13 }14 }15 result.add(new ArrayList (item));16 }17 return result;18 }19 }