<awangdev>42. Trapping Rain Water_3.java
public int trap(int[] heights) {
        if (heights == null || heights.length == 0) return 0;

        int maxIndex = 0;
        for (int i = 0; i < heights.length; i++) {
            if (heights[i] > heights[maxIndex]) maxIndex = i;
        }

        int sum = 0, prev = 0;
        for (int i = 0; i < maxIndex; i++) {
            if (heights[i] > prev) {
                sum += (maxIndex - i) * (heights[i] - prev);
                prev = heights[i];
            }
            sum -= heights[i];
        }

        prev = 0;
        for (int i = heights.length - 1; i > maxIndex; i--) {
            if (heights[i] > prev) {
                sum += (i - maxIndex) * (heights[i] - prev);
                prev = heights[i];
            }
            sum -= heights[i];
        }

        return sum;
    }
public int sample_funcname ( int [ ] var_0 ) {
  if ( var_0 == null || var_0 . length == 0 ) return 0 ;
  int var_4 = 0 ;
  for ( int var_5 = 0 ;
  var_5 < var_0 . length ;
  var_5 ++ ) {
    if ( var_0 [ var_5 ] > var_0 [ var_4 ] ) var_4 = var_5 ;
  }
  int var_6 = 0 , var_7 = 0 ;
  for ( int var_5 = 0 ;
  var_5 < var_4 ;
  var_5 ++ ) {
    if ( var_0 [ var_5 ] > var_7 ) {
      var_6 += ( var_4 - var_5 ) * ( var_0 [ var_5 ] - var_7 ) ;
      var_7 = var_0 [ var_5 ] ;
    }
    var_6 -= var_0 [ var_5 ] ;
  }
  var_7 = 0 ;
  for ( int var_5 = var_0 . length - 1 ;
  var_5 > var_4 ;
  var_5 -- ) {
    if ( var_0 [ var_5 ] > var_7 ) {
      var_6 += ( var_5 - var_4 ) * ( var_0 [ var_5 ] - var_7 ) ;
      var_7 = var_0 [ var_5 ] ;
    }
    var_6 -= var_0 [ var_5 ] ;
  }
  return var_6 ;
}
