LeetCode – 118. Pascal’s Triangle

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] ]  
Pascal's triangle is initially quite confusing, but it becomes easier once you find the pattern.

public class Solution { public List> generate(int numRows) { List> res = new ArrayList>(); if(numRows<1) return res; List first = new ArrayList(); first.add(1); res.add(first); for(int i=1;i list = new ArrayList(); list.add(1); for(int j=1;j 

This siteOriginal articleAll follow "Attribution-NonCommercial-ShareAlike 4.0 License (CC BY-NC-SA 4.0)Please retain the following annotations when sharing or adapting:

Original author:Jake Tao,source:「LeetCode – 118. Pascal’s Triangle」

156
0 0 156

Further Reading

Post a reply

Log inYou can only comment after that.
Share this page
Back to top