Description
Given an integer numRows, return the first numRows of Pascal's triangle. In Pascal's triangle, each number is the sum of the two numbers directly above it.
Examples
Input:
numRows = 5Output:
[[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]Explanation:
Each row starts and ends with 1. Interior values are sums of adjacent values above: row 2 has 2=1+1, row 3 has 3=1+2 and 3=2+1, row 4 has 4=1+3, 6=3+3, 4=3+1.
Input:
numRows = 1Output:
[[1]]Explanation:
The first row of Pascal's triangle always contains just [1]. This is the base case from which all subsequent rows are built.
Input:
numRows = 4Output:
[[1],[1,1],[1,2,1],[1,3,3,1]]Explanation:
The first 4 rows of Pascal's triangle. Row 0 has [1], row 1 has [1,1], row 2 has [1,2,1] where 2 = 1+1, and row 3 has [1,3,3,1] where the first 3 = 1+2 and the second 3 = 2+1 from the row above.
Constraints
- •
1 ≤ numRows ≤ 30