comefrom: <awangdev>265. Paint House II_3.java
code: public int minCostII(int[][] costs) {
          if (costs == null || costs.length == 0) {
              return 0;
          } else if (costs.length == 1 && costs[0].length == 1) {
              return costs[0][0];
          }
          int minCost = Integer.MAX_VALUE;
          int n = costs.length;
          int k = costs[0].length;
          int[][] dp = new int[n + 1][k];
          for (int j = 0; j < k; j++) {
              dp[0][j] = 0;
          }
  
          for (int i = 1; i <= n; i++) { 
              int minIndex = -1;
              int minSecIndex = -1;
              for (int j = 0; j < k; j++) {
                  if (minIndex == -1 || dp[i - 1][j] < dp[i - 1][minIndex]) {
                      minSecIndex = minIndex;
                      minIndex = j;
                  } else if (minSecIndex == -1 || dp[i - 1][j] < dp[i - 1][minSecIndex]) {
                      minSecIndex = j;
                  }
              }
  
              for (int j = 0; j < k; j++) { 
                  if (j == minIndex) { 
                      dp[i][j] = dp[i - 1][minSecIndex] + costs[i - 1][j];
                  } else { 
                      dp[i][j] = dp[i - 1][minIndex] + costs[i - 1][j];
                  }
                  
                  if (i == n) {
                      minCost = Math.min(minCost, dp[i][j]);   
                  }
              }
  
          }
          return minCost;
       }
masked: public int sample_funcname ( int [ ] [ ] var_0 ) {
    if ( var_0 == null || var_0 . length == 0 ) {
      return 0 ;
    }
    else if ( var_0 . length == 1 && var_0 [ 0 ] . length == 1 ) {
      return var_0 [ 0 ] [ 0 ] ;
    }
    int var_7 = Integer . MAX_VALUE ;
    int var_8 = var_0 . length ;
    int var_9 = var_0 [ 0 ] . length ;
    int [ ] [ ] var_10 = new int [ var_8 + 1 ] [ var_9 ] ;
    for ( int var_11 = 0 ;
    var_11 < var_9 ;
    var_11 ++ ) {
      var_10 [ 0 ] [ var_11 ] = 0 ;
    }
    for ( int var_12 = 1 ;
    var_12 <= var_8 ;
    var_12 ++ ) {
      int var_13 = - 1 ;
      int var_14 = - 1 ;
      for ( int var_11 = 0 ;
      var_11 < var_9 ;
      var_11 ++ ) {
        if ( var_13 == - 1 || var_10 [ var_12 - 1 ] [ var_11 ] < var_10 [ var_12 - 1 ] [ var_13 ] ) {
          var_14 = var_13 ;
          var_13 = var_11 ;
        }
        else if ( var_14 == - 1 || var_10 [ var_12 - 1 ] [ var_11 ] < var_10 [ var_12 - 1 ] [ var_14 ] ) {
          var_14 = var_11 ;
        }
      }
      for ( int var_11 = 0 ;
      var_11 < var_9 ;
      var_11 ++ ) {
        if ( var_11 == var_13 ) {
          var_10 [ var_12 ] [ var_11 ] = var_10 [ var_12 - 1 ] [ var_14 ] + var_0 [ var_12 - 1 ] [ var_11 ] ;
        }
        else {
          var_10 [ var_12 ] [ var_11 ] = var_10 [ var_12 - 1 ] [ var_13 ] + var_0 [ var_12 - 1 ] [ var_11 ] ;
        }
        if ( var_12 == var_8 ) {
          var_7 = Math . min ( var_7 , var_10 [ var_12 ] [ var_11 ] ) ;
        }
      }
    }
    return var_7 ;
  }
  