233. Pascal's Triangle

Easy
Row Simulation
Array

Problem

Given an integer numRows, return the first numRows of Pascal's triangle. Each interior value is the sum of the two values directly above it.

Examples

Example 1

Input: 5
Output: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]

Example 2

Input: 1
Output: [[1]]

Example 3

Input: 2
Output: [[1],[1,1]]
Constraints

1 <= numRows <= 30

Hints

?? Every row begins and ends with 1.

?? Interior elements can be computed from the previous row.

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

Can you generate each row using only the previously generated row?

Practice Notes

Attempts: 0

Time spent: 0min

Hints used: 0

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