Python easy to understand and simple code, 100%


  • 0
    P

    bottom-up, modify in-place

    class Solution(object):
        def minimumTotal(self, triangle):
            """
            :type triangle: List[List[int]]
            :rtype: int
            """
            if triangle == [[]]:
                return 0
            triangle.sort( key=len, reverse=True )
            for i, row in enumerate(triangle):
                for j in range(len(row)-1):
                    triangle[i+1][j] += min( row[j], row[j+1] )
            return triangle[-1][0]
    

Log in to reply
 

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