The key ideas are:

  1. We start from two edges and move to the middle with two pointers.
  2. Move the pointer to the middle which side is smaller.
class Solution {
public:
	int maxArea(vector<int>& height) {
		int i = 0, j = height.size() - 1;
		int water = 0;
		while (i < j) {
			water = max(water, (j - i) * min(height[i], height[j]));
			if (height[i] > height[j]) {
				--j;
			} else {
				++i;
			}
		}
		return water;
	}
};