public int trap(int[] A) {
		if(A == null || A.length == 0) return 0;
		Stack<Integer> stack = new Stack<Integer>();
		int res = 0, i = 0;
		while(i < A.length) {
			if(stack.isEmpty()) {
				if(A[i] > 0) stack.add(i++);
				else i++; // bug, forgot this
			} else if(A[i] < A[stack.peek()]) {
				stack.add(i++);
			} else if(A[i] >= A[stack.peek()]) { // bug, need = here
				int pre = stack.pop();
				if(stack.isEmpty()) {
					stack.add(i++);
				} else {
					int height = (Math.min(A[i], A[stack.peek()])) - A[pre];
					res += height * (i - 1 - stack.peek());
				}
			}
		}
		return res;
	}