Python: easy to understand


  • 0
    P
    class Solution(object):
        def minimumTotal(self, triangle):
            """
            :type triangle: List[List[int]]
            :rtype: int
            """
            for i in range(len(triangle)):
            	for j in range(len(triangle[i])):
            		upNode = self.findUpNode(i, j, triangle)
            		triangle[i][j] += min(upNode)
            		# print( upNode, triangle[i][j] )
           	return min(triangle[-1])
    
    
        def findUpNode(self, i, j, triangle):
        	if i==0 and j==0:
        		return [0,0]
        	if j==0:
        		return [float('inf'), triangle[i-1][0]]
        	if j==i:
        		return [triangle[i-1][-1], float('inf')]
        	return [triangle[i-1][j-1], triangle[i-1][j]]
    

Log in to reply
 

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