public int trap(int[] A){
  if (A == null || A.length == 0)   return 0;
  int l=0;
  int r=A.length - 1;
  int level=0;
  int all=0;
  int block=0;
  while (l <= r) {
    int curLevel=Math.min(A[l],A[r]);
    if (curLevel > level) {
      all+=(curLevel - level) * (r - l + 1);
      level=curLevel;
    }
    if (A[l] < A[r])     block+=A[l++];
 else     block+=A[r--];
  }
  return all - block;
}

public int trap ( int [ ] A ) { if ( A == null || A . length == 0 ) return 0 ; int l = 0 ; int r = A . length - 1 ; int level = 0 ; int all = 0 ; int block = 0 ; while ( l <= r ) { int curLevel = Math . min ( A [ l ] , A [ r ] ) ; if ( curLevel > level ) { all += ( curLevel - level ) * ( r - l + 1 ) ; level = curLevel ; } if ( A [ l ] < A [ r ] ) block += A [ l ++ ] ; else block += A [ r -- ] ; } return all - block ; }
calculate the area of all and blocks then return all - block to get the trapped water start from two sides if min of a [ l ] and a [ r ] is larger than current level update all and curlevel then move lower pointer towards center
