The topics are as follows:
Given numrows, generate the first numrows of Pascal ' s triangle.
For example, given numrows = 5,
Return
[ 1], [ 1,2,1], [ 1,3,3,1], [ 1,4,6,4,1]
The implementation code is as follows:
public class Solution {public list<list<integer>> generate (int numrows) { list<list< integer>> res = new arraylist<list<integer>> (); if (numrows<1) {return res;} list<integer> row1 = new arraylist<integer> () Row1.add (1); Res.add (ROW1); if (numrows==1) {return res;} for (int i =1;i<numrows; ++i) {list<integer> row = new arraylist<integer> (), Row.add (1); for (int j=1;j<i ; ++j) {Row.add (J,res.get (i-1). Get (J-1) +res.get (i-1). Get (j)); Row.add (1); Res.add (row);} return res; }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
(leetcode) Yang Hui triangle Pascal ' s Triangle