Triangle
MediumP3Coding
triangle is a list of rows where row r has r + 1 integers. Starting from the single number in the top row, you move down one row at a time. From position c in row r you may step to position c or c + 1 in row r + 1.
Return the smallest possible sum of the numbers on a path from the top to the bottom row.
Example 1
- Input
- triangle = [[2],[3,4],[6,5,7],[4,1,8,3]]
- Output
- 11
- Why
- The path 2 + 3 + 5 + 1 = 11.
Example 2
- Input
- triangle = [[-10]]
- Output
- -10
Example 3
- Input
- triangle = [[1],[2,3]]
- Output
- 3
Constraints
- 1 <= triangle.length <= 200
- -10^4 <= triangle[r][c] <= 10^4
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.