class Solution(object): def minimumTotal(self, triangle): """ :type triangle: List[List[int]] :rtype: int """ if triangle is None or len(triangle) == 0: return 0 ls = len(triangle) dp =  * ls dp = triangle for i in range(1, ls): # note that dp should be updated in reversed order dp[i] = dp[i - 1] + triangle[i][i] for j in reversed(range(1, i)): dp[j] = min(dp[j - 1] + triangle[i][j], dp[j] + triangle[i][j]) dp = dp + triangle[i] return min(dp)
Leetcode 120 Triangle problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.
Feedback is the most important part of any website.
If you have any query, suggestion or feedback, Please feel free to contact us.