题解 | #三角形最小路径和#
三角形最小路径和
https://www.nowcoder.com/practice/c9d44b73dc7c4dbfa4272224b1f9b42c
class Solution: def minTrace(self , triangle: List[List[int]]) -> int: n = len(triangle) new = triangle[-1].copy() for i in reversed(range(n-1)): for j in range(i+1): new[j] = triangle[i][j] + min(new[j+1], new[j]) return new[0]