标签:
Description:
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>> list = new ArrayList<List<Integer>>(); for(int i=0; i<numRows; i++) { List<Integer> tList = new ArrayList<Integer>(); if(i == 0) { tList.add(1); } else { for(int j=0; j<=i; j++) { if(j == 0 || j == i) { tList.add(1); } else { tList.add(list.get(i-1).get(j) + list.get(i-1).get(j-1)); } } } list.add(tList); } return list; } }
标签:
原文地址:http://www.cnblogs.com/wxisme/p/4589795.html