leetcode 265. Paint House II

leetcode 265. Paint House II


class Solution {
    public int minCostII(int[][] costs) {
        int N = costs.length;
        if(N==0) return 0;
        int k = costs[0].length;
        if(k==1&&N==1)  return costs[0][0];
        int[][] dp = new int[N+1][k];
        for(int i=1;i<=N;i++){
            int min_1 = dp[i-1][0]>dp[i-1][1]?dp[i-1][1]:dp[i-1][0];
            int index_1 = dp[i-1][0]>dp[i-1][1]?1:0;
            int min_2 = dp[i-1][0]>dp[i-1][1]?dp[i-1][0]:dp[i-1][1];
            int index_2 = dp[i-1][0]>dp[i-1][1]?0:1;
            for(int j=2;j


你可能感兴趣的:(算法)