Mid/Senior
Paint House
There is a row of n houses, and each house can be painted one of three colors: red, blue, or green. The cost of painting each house with each color is given by a 2D integer array costs, where costs[i][0], costs[i][1], and costs[i][2] are the costs of painting house i red, blue, and green, respectively.
You must paint all houses such that no two adjacent houses have the same color.
Return the minimum total cost to paint all houses.
Example 1
Input
costs = [[17,2,17],[16,16,5],[14,3,19]]Output
10Paint house 0 blue, house 1 green, and house 2 blue for a total cost of 2 + 5 + 3 = 10.
Example 2
Input
costs = [[7,6,2]]Output
2With only one house, choose the cheapest color, which costs 2.
Constraints
- costs.length == n
- costs[i].length == 3
- 1 <= n <= 100
- 1 <= costs[i][j] <= 20