Paint House

来源:互联网 发布:智慧医疗 物联网 知乎 编辑:程序博客网 时间:2024/06/08 17:31

想想想

public class Solution {    public int minCost(int[][] costs) {        if (costs == null || costs.length == 0) {    return 0;    }      for (int i = 1; i < costs.length; i++) {    costs[i][0] = costs[i][0] + Math.min(costs[i - 1][1], costs[i - 1][2]);    costs[i][1] = costs[i][1] + Math.min(costs[i - 1][0], costs[i - 1][2]);    costs[i][2] = costs[i][2] + Math.min(costs[i - 1][0], costs[i - 1][1]);    }    return Math.min(costs[costs.length - 1][0], Math.min(costs[costs.length - 1][1], costs[costs.length - 1][2]));    }}


0 0