Simple Python Solution for Paint House I and Paint House II

  • 0

    A simple python solution for Paint House II.

    Repurposed Paint House I Solution over here:

        def minCostII(self, costs):
            :type costs: List[List[int]]
            :rtype: int
            if not costs or not len(costs[0]):
                return 0
            k = len(costs[0]) # Number of colors
            for i in range(1, len(costs)):# For all the houses
                for j in range(0, k):
                    exclude = costs[i-1][j]
                    costs[i-1][j] = sys.maxint 
                    costs[i][j] += min(costs[i-1])
                    costs[i-1][j] = exclude
            return min(costs[-1])

    It works for both Paint House I and Paint House II solutions.

Log in to reply

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