Simple Python DP


  • 1
    class Solution(object):
        def minCostII(self, costs):
            """
            :type costs: List[List[int]]
            :rtype: int
            """
            if not costs:
                return 0
            for i in range(1,len(costs)):
                for k in range(len(costs[0])):
                    costs[i][k] += min(costs[i-1][:k]+costs[i-1][k+1:])
            return min(costs[-1])

Log in to reply
 

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