public int trap2(int[] height) {
        if (height == null) return -1;
        int[] left = new int[height.length];
        int leftMax = 0;
        for (int i = 0; i < height.length; ++i) {
            leftMax = Math.max(leftMax, height[i]);
            left[i] = leftMax;
        }
  
        int rightMax = 0;
        int rain = 0;
        for (int i = height.length - 1; i >= 0; --i) {
            rightMax = Math.max(rightMax, height[i]);
            int diff = Math.min(rightMax, left[i]);
            if (diff - height[i] > 0) rain += diff - height[i];
        }
        return rain;
    }