EricssonOA #1
Pascal's Triangle
EasyJudge-ready
Topics (AI-labelled)DP Basics
Given a non-negative integer numRows, return the first numRows rows of Pascal's triangle.
Input
A single integer numRows (0≤numRows≤30).
Output
Output a compact JSON 2D integer array; output [] when numRows=0.
Example 1
Input:
0
Output:
[]
Example 2
Input:
5
Output:
[[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]
Example notes
Build each new row from the sums of adjacent elements in the previous row.
Editorial
Loading solution…