Skip to content

Instantly share code, notes, and snippets.

@terracotta-ko
Created June 28, 2017 14:45
gist for leetcode 11
public class Solution {
public int maxArea(int[] height) {
int ans = 0;
int left = 0, right = height.length-1;
while(left < right) {
if(height[left] < height[right]) {
ans = Math.max(ans, (right-left) * height[left]);
++left;
}
else {
ans = Math.max(ans, (right-left) * height[right]);
--right;
}
}
return ans;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment