Triangle

The problem is to find the minimum path sum from top to bottom if given a triangle. Each step you may move to adjacent numbers on the row below.

Input

  • triangle: see example

Output

the minimum path sum

Examples

Example 1:

Input:

1triangle = [
2     [2],
3    [3,4],
4   [6,5,7],
5  [4,1,8,3]
6]
7

Output: 11

Explanation:

The minimum path sum from top to bottom is 2 + 3 + 5 + 1 = 11.

Try it yourself

Solution

←
↑TA πŸ‘¨β€πŸ«