11. Container With Most Water
2016-10-18 本文已影响0人
FlynnLWang
Question Description

My Code
public class Solution {
public int maxArea(int[] height) {
int result = 0;
int i = 0, j = height.length - 1;
while (i < j) {
int x = j - i;
int y = Math.min(height[i], height[j]);
int area = x * y;
result = area > result ? area : result;
if (height[i] < height[j]) i++;
else j--;
}
return result;
}
}
Test Result
