双指针可以变为但指针鸭,每个容器都取决于短的那条边,每次改变那条边就行了
class Solution {
public int maxArea(int[] height) {
int maxSize=0;
int leftIndex=0,RightIndex=height.length-1;
while(leftIndex<RightIndex){
maxSize=Math.min(height[leftIndex],height[RightIndex])*(Math.abs(leftIndex - RightIndex))>maxSize?Math.min(height[leftIndex],height[RightIndex])*(Math.abs(leftIndex - RightIndex)):maxSize;
if(height[leftIndex]<height[RightIndex]){
leftIndex++;
}
else{
RightIndex--;
}
}
return maxSize;
}
}