Given an integer numRows, return the first numRows of Pascal’s triangle.
Number of Rows in Pascal Triangle
List containing arrays representing rows of Pascal Triangle
the iterative approach to constructing Pascal’s triangle can be classified as dynamic programming because we construct each row based on the previous row.
First, we generate the overall
triangle list, which will store each row as a sublist. Then, we check for the special case of 00, as we would otherwise return . Since numRowsnumRows is always greater than 00, we can initialize
triangle with  as its first row, and proceed to fill the rows as follows:
Time complexity: O(NumRows²)
Space complexity: O(1)
Thanks for Reading
Placewit grows the best engineers by providing an interactive classroom experience and by helping them develop their skills and get placed in amazing companies.