234. Pascal's Triangle II

Easy
One-Dimensional DP
Array

Problem

Given a zero-based rowIndex, return the rowIndex-th row of Pascal's triangle.

Examples

Example 1

Input: 3
Output: [1,3,3,1]

Example 2

Input: 0
Output: [1]

Example 3

Input: 1
Output: [1,1]
Constraints

0 <= rowIndex <= 33

Hints

?? A row can be updated from the previous row.

?? When updating a single array, process positions from right to left so old values are not overwritten too early.

Expected Complexity
Time: O(rowIndex^2)
Space: O(rowIndex)
Follow-up

Can you solve it using only O(rowIndex) extra space?

Practice Notes

Attempts: 0

Time spent: 0min

Hints used: 0

00:00
Loading...
Case 1
Case 2
Case 3
Input
3
Expected
[1,3,3,1]