标签:leetcode val etc int nbsp max ini tco for
class Solution { public int minCostII(int[][] costs) { if (costs.length == 0) { return 0; } int prevMin = 0; int prevSecMin = 0; int prevMinIndex = -1; for (int i = 0; i < costs.length; i++) { int min = Integer.MAX_VALUE; int secMin = Integer.MAX_VALUE; int minIndex = -1; for (int j = 0; j < costs[i].length; j++) { int value = costs[i][j] + (j == prevMinIndex ? prevSecMin : prevMin); if (minIndex == -1 || value < min) { secMin = min; min = value; minIndex = j; } else if (value < secMin) { secMin = value; } } prevMin = min; prevSecMin = secMin; prevMinIndex = minIndex; } return prevMin; } }
标签:leetcode val etc int nbsp max ini tco for
原文地址:http://www.cnblogs.com/shuashuashua/p/7479175.html