题解 | #三角形最小路径和#
三角形最小路径和
https://www.nowcoder.com/practice/c9d44b73dc7c4dbfa4272224b1f9b42c
from functools import cache # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param triangle int整型二维数组 # @return int整型 # class Solution: def minTrace(self , tri: List[List[int]]) -> int: # write code here r = len(tri) @cache def dfs(i,j): if i==r-1: return tri[i][j] return min(dfs(i+1,j),dfs(i+1,j+1)) + tri[i][j] return dfs(0,0)