public int trap(int[] height) {
        if (height == null) return -1;
        int left = 0, right = height.length - 1;
        int leftMax = 0, rightMax = 0, rain = 0;
        while (left <= right) {
            if (height[left] <= height[right]) {
                if (height[left] > leftMax) leftMax = height[left];
                else rain += leftMax - height[left];
                ++left;
            } else {
                if (height[right] > rightMax) rightMax = height[right];
                else rain += rightMax - height[right];
                --right;
            }
        }
        return rain;
    }