题目
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).Note:
Bonus point if you are able to do this using only O(n) extra space, where n is the total number of rows in the triangle.
递归方法
这道题的数据结构很像二叉树的结构,我们可以用递归遍历二叉树的思想来遍历所有的可能的路径,以求出最小的路径权重和。
定义一个辅助的递归函数 int myRecursion(vector<vector<int>>& triangle, int i, int j),这个第一个参数为原三角形,第二和第三个参数(i,j)代表当前遍历到的三角形的节点位置,返回值为以当前节点(i&#