Python3 Solution (Runtime @ 100.00% Percentile)


  • 0
    M
    class Solution:
        def minimumTotal(self, triangle):
            """
            :type triangle: List[List[int]]
            :rtype: int
            """
            # assert triangle != []
            
            """
            Bottom-up solution
            """
            row_mins = triangle[-1]
            for i in range(len(triangle) - 2, -1, -1):
                row = triangle[i]
                current_row_mins = []
                for j in range(len(row)):
                    current_row_mins.append(
                        min(row_mins[j], row_mins[j + 1]) + row[j])
                row_mins = current_row_mins
            
            return row_mins[0]
    

Log in to reply
 

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