import java.util.Stack;
public class TrappingRainWater {
public int trap(int[] height) {
int left = 0;
int right = height.length - 1;
int res = 0;
int leftMax = 0;
int rightMax = 0;
while (left < right) {
if (height[left] < height[right]) {
leftMax = Math.max(height[left], leftMax);
res += leftMax - height[left];
left++;
} else {
rightMax = Math.max(height[right], rightMax);
res += rightMax - height[right];
right--;
}
}
return res;
}
public int trap1(int[] A) {
if (A==null) return 0;
Stack