刚开始做的思路知道是使用双指针,但是思维有点局限于只能移动某一个指针,靠着固定指针i,滑动指针j,来寻找最大值。
class Solution {
public int maxArea(int[] height) {
// 同时移动两个指针
int n = height.length;
int ans = 0;
int i = 0;
int j = n-1;
while(i!=j){
ans = Math.max(ans,Math.min(height[i],height[j])*(j-i));
if(height[i]<height[j]){
i++;
}else{
j--;
}
}
return ans;
}
}