Loading...
You are given a two-dimensional list of integers costs where costs[i][j] is the cost of painting the ith fence in a row with color j.
costs
costs[i][j]
i
j
Paint every fence with exactly one color so that no two adjacent fences share a color. You can assume there are at least 2 colors.
2
Return the minimum total cost.
Input: costs = [[17,2,17],[16,16,5],[14,3,19]] Output: 10 Explanation: Paint the fences with colors 1, 2, 1 (0-indexed): 2 + 5 + 3 = 10.
Input: costs = [[1,5],[5,1]] Output: 2 Explanation: Paint the fences with colors 0, 1: 1 + 1 = 2.
Input: costs = [[7,3,8,6,1,2]] Output: 1 Explanation: A single fence, so the cheapest color wins.
costs.length
costs[0].length