solution.cpp 336 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) > (b)) ? (b) : (a))
int maxArea(int *height, int heightSize)
{
	int max = 0;
	int i = 0, j = heightSize - 1;
	int a;
	while (i < j)
	{
		a = MIN(height[i], height[j]) * (j - i);
		max = MAX(max, a);
		if (height[i] > height[j])
			--j;
		else
			++i;
	}
	return max;
}