Python: runtime beats 100.00% of python submissions


  • 0
    S
    def minimumTotal(self, triangle):
        if not triangle or not triangle[0]: return float("-inf")
        arr=[float("inf") for i in range(len(triangle)+1)]
        arr[1]=0
        for i in range(1, len(triangle)+1):
            for j in range(len(triangle[i-1]), 0, -1):
                arr[j]=min(arr[j-1],arr[j])+triangle[i-1][len(triangle[i-1])-j]
        return min(arr[1:])

Log in to reply
 

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