LeetCode icon indicating copy to clipboard operation
LeetCode copied to clipboard

256. Paint House

Open LLancelot opened this issue 5 years ago • 1 comments

image

LLancelot avatar Mar 11 '20 02:03 LLancelot

class Solution:
    def minCost(self, costs: List[List[int]]) -> int:
        if not costs:
            return 0
        if len(costs) == 1:
            return min(costs[0])
        
        for n in range(1, len(costs)):
            costs[n][0] = min(costs[n-1][1], costs[n-1][2]) + costs[n][0]
            costs[n][1] = min(costs[n-1][0], costs[n-1][2]) + costs[n][1]
            costs[n][2] = min(costs[n-1][0], costs[n-1][1]) + costs[n][2]

        return min(costs[-1])

LLancelot avatar Mar 11 '20 02:03 LLancelot