public class Solution {
public int MaxArea(int[] height) {
if (height == null)
{
return 0;
}
int start = 0;
int end = height.Length - 1;
int max = 0;
while (start < end)
{
int current = (end - start) * Math.Min(height[start], height[end]);
max = Math.Max(max, current);
if (height[start] < height[end] && end > start + 1)
{
start++;
continue;
}
if (height[start] > height[end] && end - 1 > start)
{
end--;
continue;
}
start++;
end--;
}
return max;
}
}
Tuesday, August 23, 2016
Leetcode 11. Container With Most Water
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment