concise Python solution using dp

  • 0

    without using extra space

        def minCost(self, costs):
            :type costs: List[List[int]]
            :rtype: int
            for i in range(1,len(costs)):
                costs[i] = [costs[i][j] + min([costs[i-1][k] for k in range(3) if k != j]) for j in range(3)]
            return min(costs[len(costs)-1]) if len(costs) > 0 else 0

Log in to reply

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