/118. Pascal's Triangle

118. Pascal's Triangle

Easy
Arrays78.7% acceptance

Given a positive integer row_count, generate a list of lists representing the first row_count rows of Pascal's triangle. Each row starts and ends with 1. Each interior element is the sum of the two elements directly above it from the previous row.

Example 1

Input: 2

Output: [[1],[1,1]]

Explanation: The first two rows are [1] and [1,1].

Example 2

Input: 4

Output: [[1],[1,1],[1,2,1],[1,3,3,1]]

Explanation: The first four rows are [1], [1,1], [1,2,1], and [1,3,3,1].

Constraints

  • 1 <= row_count <= 30
Python (current runtime)

Case 1

Input: 3

Expected: [[1],[1,1],[1,2,1]]

Case 2

Input: 6

Expected: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1],[1,5,10,10,5,1]]

Case 3

Input: 5

Expected: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]