[LeetCode] 256. Paint House

[复制链接]
发表于 2022-8-10 09:04:41 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
There is a row of n houses, where each house can be painted one of three colors: red, blue, or green. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses have the same color.
The cost of painting each house with a certain color is represented by an n x 3 cost matrix costs.

  • For example, costs[0][0] is the cost of painting house 0 with the color red; costs[1][2] is the cost of painting house 1 with color green, and so on...
Return the minimum cost to paint all houses.
Example 1:
  1. Input: costs = [[17,2,17],[16,16,5],[14,3,19]]
  2. Output: 10
  3. Explanation: Paint house 0 into blue, paint house 1 into green, paint house 2 into blue.
  4. Minimum cost: 2 + 5 + 3 = 10.
复制代码
Example 2:
  1. Input: costs = [[7,6,2]]
  2. Output: 2
复制代码
Constraints:
<ul>costs.length == n
costs.length == 3
1
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表