LeetCode p120 Triangle 题解
1.题目:
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.
For example, given the following triangle
[
[2],
[3,4],
[6,5,7],
[4,1,8,3]
]
The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + 1 = 11).
题意:
求一三角状数组,从顶部到底部的路径中,和值最小的那条路径的和值。
2.解题思路:
从底部往上走,每次累加自己相邻底部的最小值,见代码。
3.代码
1 |
|