bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 118. Pascal's Triangle

118. Pascal's Triangle

Leetcode Solutions

Dynamic Programming Approach to Construct Pascal's Triangle

  1. Initialize an empty list triangle to hold the rows of Pascal's Triangle.
  2. Add the first row [1] to triangle.
  3. For each row from 2 to numRows: a. Create a new row list with the first element as 1. b. For each element from the second to the second last in the previous row, add the sum of the element and the element before it to the new row. c. Append 1 to the new row to complete it. d. Add the new row to triangle.
  4. Return triangle after all rows have been added.
UML Thumbnail

Recursive Approach to Construct Pascal's Triangle

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...