public int trap(int[] A) {
		if (A.length <= 2)
			return 0;
		int[] leftMax = new int[A.length];
		int[] rightMax = new int[A.length];
		int total = 0;
		int max = A[0];
		for (int i = 1; i < A.length; i++) {
			leftMax[i] = max;
			if (A[i] > max)
				max = A[i];
		}
		max = A[A.length - 1];
		for (int i = A.length - 1 - 1; i > 0; i--) {
			rightMax[i] = max;
			int temp = Math.min(leftMax[i]-A[i], rightMax[i] - A[i]);
			if (temp >= 0)
				total += temp;
			if (A[i] > max)
				max = A[i];
		}

		return total;
	}