题目
思路
自底向上遍历,滚动数组。
代码
class Solution:
def minimumTotal(self, triangle):
"""
:type triangle: List[List[int]]
:rtype: int
"""
dp = [i for i in triangle[len(triangle) - 1]]
for i in range(len(triangle) - 1)[::-1]:
for j in range(len(triangle[i])):
dp[j] = min(dp[j], dp[j + 1]) + triangle[i][j]
return dp[0]