Your code is easy to understand! I just merge the initialization into the second part based on your code.

class Solution {
public:
int minCostII(vector<vector<int>>& costs) {
if (!costs.size() || !costs[0].size()) {
return 0;
}
int min1 = 0; // the smallest costs of the previous house
int min2 = 0; // the second smallest costs of the previous house
int index1 = -1;// index of the smallest costs in previous step.
for (int i = 0; i < costs.size(); i++) {
int tmp1 = INT_MAX,tmp2 = INT_MAX;
int ind1 = 0;
for (int j = 0; j < costs[0].size(); j++) {
int c = (j == index1 ? min2 : min1) + costs[i][j];
// record the 2 minimum costs in this step
if (c < tmp1) {
tmp2 = tmp1;
tmp1 = c;
ind1 = j;
}
else if (c < tmp2) {
tmp2 = c;
}
}
min1 = tmp1, min2 = tmp2, index1 = ind1;
}
return min1;
}
};