/119. Pascal's Triangle II

119. Pascal's Triangle II

Easy
Arrays67.2% acceptance

Given a non-negative integer n, return the nth row (0-indexed) of Pascal's Triangle as a list of integers. Each element in the row is the sum of the two elements directly above it from the previous row, with the first and last elements always being 1.

Example 1

Input: 4

Output: [1, 4, 6, 4, 1]

Explanation: The 4th row of Pascal's Triangle is [1, 4, 6, 4, 1].

Example 2

Input: 2

Output: [1, 2, 1]

Explanation: The 2nd row of Pascal's Triangle is [1, 2, 1].

Example 3

Input: 5

Output: [1, 5, 10, 10, 5, 1]

Explanation: The 5th row of Pascal's Triangle is [1, 5, 10, 10, 5, 1].

Constraints

  • 0 <= n <= 33
Python (current runtime)

Case 1

Input: 6

Expected: [1, 6, 15, 20, 15, 6, 1]

Case 2

Input: 7

Expected: [1, 7, 21, 35, 35, 21, 7, 1]

Case 3

Input: 8

Expected: [1, 8, 28, 56, 70, 56, 28, 8, 1]

Case 4

Input: 3

Expected: [1, 3, 3, 1]

Case 5

Input: 1

Expected: [1, 1]