题目
https://leetcode.cn/problems/triangle/description/?envType=study-plan-v2&envId=dynamic-programming
题解
1 2 3 4 5 6 7 8 9 10 11 12 13
| class Solution: def minimumTotal(self, triangle: List[List[int]]) -> int: n = len(triangle) lst = [[0 for i in range(j)] for j in range(1,n+1)]
for i in range(n): lst[n-1][i] = triangle[n-1][i]
for i in range(n-2,-1,-1): for j in range(i+1): lst[i][j] = triangle[i][j] + min(lst[i+1][j], lst[i+1][j+1])
return lst[0][0]
|