question: 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 ; }
target:  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