]
The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + 1 = 11).
这道题目采用动态规划,从最底下往上依次相加得到解。
this is a DP problem, we can solve this problem by suming up from the bottom to the top.
class Solution: # @param triangle, a list of lists of integers # @return an integer def minimumTotal(self, triangle): rownum=len(triangle) for index in reversed(range(rownum)): if index==rownum-1: m=triangle[index] else: for j in range(index+1): m[j]=triangle[index][j]+min(m[j],m[j+1]) return m[0]
原文地址:http://blog.csdn.net/hyperbolechi/article/details/42863865