Container With Most Water
Notice
public class Solution {
/*
* @param heights: a vector of integers
* @return: an integer
*/
public int maxArea(int[] heights) {
// write your code here
int n = heights.length;
int start = 0, end = n-1;
int area = 0;
while(start < end){
if(heights[end] > heights[start]){
area = Math.max(area, heights[start] * (end - start));
start ++;
}
else{
area = Math.max(area, heights[end] * (end - start));
end --;
}
}
return area;
}
}Last updated