public int trap(int[] A) {
		if(A == null || A.length == 0) return 0;
		int res = 0, pos = 0;
		Stack<Integer> stack = new Stack<Integer>();
		
		while(pos < A.length){
			if(stack.isEmpty()){
				if(A[pos] > 0) stack.push(pos);
				pos++;
			} else {
				if(A[pos] < A[stack.peek()]){
					stack.push(pos++);
				} else if(A[pos] == A[stack.peek()]){
					stack.pop();
					stack.push(pos++);
				} else {
					if(stack.size() == 1){
						stack.pop();
						stack.push(pos++);
					} else {
						int bottom = A[stack.pop()];
						int length = pos - 1 - stack.peek();
						int hight = getMin(A[pos], A[stack.peek()]);
						res += (hight - bottom) * length;
					}
				}
			}
		}
		
		return res;
	}