11. Container With Most Water
2016-10-18 本文已影响0人
FlynnLWang
Question Description
Screen Shot 2016-10-17 at 22.29.35.pngMy 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;
}
}