Share my short python DP code

  • 0

    From bottom to the top, DP

    class Solution(object):
    def minimumTotal(self, triangle):
        if len(triangle)==1: return triangle[0][0]
        temp, res=triangle[-1], []
        for i in xrange(-2, -len(triangle)-1, -1):
            for j in xrange(len(triangle[i])):
                res+=min(temp[j], temp[j+1])+triangle[i][j],
            temp, res=res, []
        return temp[0]

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.