11 Container With Most Water
1. Question
2. Implementation
class Solution {
public int maxArea(int[] height) {
int res = 0;
int start = 0, end = height.length - 1, curHeight = Integer.MAX_VALUE;
while (start < end) {
curHeight = Math.min(height[start], height[end]);
res = Math.max(res, curHeight * (end - start));
if (height[start] <= curHeight) {
++start;
}
else {
--end;
}
}
return res;
}
}3. Time & Space Complexity
Last updated