Pascal's triangle is a pyramid of numbers, built one row at a time. The top row is just 1. Every row begins with 1 and ends with 1.
Each number between those two ends is the sum of the two numbers diagonally above it, in the row before.
For example, the row after [1,2,1] is [1,3,3,1]. The new middle numbers are 1 + 2 and 2 + 1.
Given a whole number numRows, return the first numRows rows of the pyramid. Each row is a list. The top row comes first.
Examples
Example 1:
Input: numRows = 4
Output: [[1],[1,1],[1,2,1],[1,3,3,1]]
Explanation: In the last row, the two 3s are 1 + 2 and 2 + 1.
Example 2:
Input: numRows = 6
Output: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1],[1,5,10,10,5,1]]
Explanation: The last row comes from [1,4,6,4,1]. Its middle numbers are 1 + 4 = 5, 4 + 6 = 10, 6 + 4 = 10 and 4 + 1 = 5.
Example 3:
Input: numRows = 8
Output: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1],[1,5,10,10,5,1],[1,6,15,20,15,6,1],[1,7,21,35,35,21,7,1]]
Explanation: The last row comes from [1,6,15,20,15,6,1]. Its middle numbers are 1 + 6 = 7, 6 + 15 = 21 and 15 + 20 = 35.