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