I see lots solutions make two point method very complicated here, where they keep both a leftMax, left and rightMax, right. Actually, it is not necessary to keep the max of both sides.

we just need 2 pointers: l and r

In each iteration, we compare height[l] and height[r], the smaller one moves.

The loop stops if l and r meets.

Note that, we calculate

```
rain[l] = max(rain[l-1] + height[l-1] - height[l], 0)
```

we use lp and rp to store the previous calculated rain volume.

```
public class Solution {
public int trap(int[] height) {
int l = 0;
int r = height.length-1;
int len = height.length;
int ret = 0;
int lp = 0;
int rp = 0;
while(l < r) {
if(height[l] <= height[r]) {
if(l > 0) {
lp = Math.max(0, height[l-1] - height[l] + lp);
ret += lp;
}
l ++;
} else {
if(r < len-1) {
rp = Math.max(0, height[r+1] - height[r] + rp);
ret += rp;
}
r --;
}
}
return ret;
}
}
```