具体思路:
双指针减少搜索空间,DP不是不可以,但是超时;
太牛批的一道题,题解更牛皮;
https://leetcode-cn.com/problems/container-with-most-water/solution/on-shuang-zhi-zhen-jie-fa-li-jie-zheng-que-xing-tu/
具体代码:
class Solution {
public:
int maxArea(vector<int>& height) {
int len=height.size();
int maxn=-1;
int i=0,j=len-1;
while(i<j){
maxn=max(maxn,min(height[i],height[j])*(j-i));
if(height[i]<height[j]){
i++;
}else{
j--;
}
}
return maxn;
}
};