Triangle
Description:
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.
Example
Given the following triangle:
[
[2],
[3,4],
[6,5,7],
[4,1,8,3]
]
Code:
class Solution:
"""
@param triangle: a list of lists of integers
@return: An integer, minimum path sum
"""
def minimumTotal(self, triangle):
# write your code here
cnt = triangle
l = len(cnt)
for i in range(l-2,-1,-1):
for j in range(len(cnt[i])):
cnt[i][j] += min(cnt[i+1][j], cnt[i+1][j+1])
return cnt[0][0]