You must paint n houses in a row, where the number of houses n is at least 1. The houses are indexed 0 to n-1.
You have three paint colors: red, green, and blue. The cost to paint house i a given color is provided in a 2D list costs, where:
costs[i][0] is the cost of painting house i redcosts[i][1] is the cost of painting house i greencosts[i][2] is the cost of painting house i blueNo two neighboring houses may be painted the same color.
Write a function minCost(costs) that returns the smallest total cost to paint every house while obeying the adjacent-color restriction.
Example 1:
Input: costs = [[3, 5, 7]]
Output: 3
Explanation: There is one house. Painting it red costs 3, which is the cheapest option.
Example 2:
Input: costs = [[2, 4, 5], [3, 9, 1], [6, 8, 2]]
Output: 9
Explanation: An optimal assignment is:
Example 3:
Input: costs = [[10, 20, 30], [15, 15, 15], [5, 4, 3]]
Output: 28
Explanation: An optimal plan costs 28: house 0 → red (10), house 1 → green (15), house 2 → blue (3). No two consecutive houses share a color.
Constraints:
n == costs.length1 <= n <= 100costs[i].length == 30 <= costs[i][j] <= 1000