public int minCostII(int[][] costs) {
        if (costs == null || costs.length == 0) return 0;

        for (int i = 1; i < costs.length; ++i) {
            int min1 = Integer.MAX_VALUE, c1 = -1;
            int min2 = Integer.MAX_VALUE;
            for (int j = 0; j < costs[0].length; ++j) {
                if (costs[i - 1][j] < min1) {
                    min2 = min1;
                    min1 = costs[i - 1][j]; c1 = j;
                } else if (costs[i - 1][j] < min2) {
                    min2 = costs[i - 1][j];
                }
            }
            for (int j = 0; j < costs[0].length; ++j) {
                costs[i][j] = costs[i][j] + (c1 != j ? min1 : min2);
            }
        }

        int minCost = Integer.MAX_VALUE;
        for (int c = 0; c < costs[0].length; ++c) {
            minCost = Math.min(minCost, costs[costs.length - 1][c]);
        }
        return minCost;
    }