classSolution:defminimumTotal(self,triangle: List[List[int]]) ->int: n =len(triangle) last = [1e12] * n last[0]= triangle[0][0]for i inrange(1, n): new_dp = [0] * nfor j inrange(i +1): new_dp[j]=min(last[j -1] if j -1>=0else1e12, last[j] if j < i else1e12)+ triangle[i][j] last = new_dpreturnmin(last)