AAlgoLab
ALG-M010MediumDynamic Programming

Build Pascal Layers

Return the first rows rows of Pascal's triangle. Each row starts and ends with 1; interior entries are the sum of the two entries above.

Contract

input rows: integer
return integer[][]

Constraints

  • • 0 <= rows <= 20

Examples

Example 1
rows = 5
→ [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1]]
Example 2
rows = 1
→ [[1]]

5 judge tests (2 shown above). Target complexity: O(rows^2).