key:
1.a group with two point from the both side.
2 calcu current area&& update maxarea && update the point with short height
3. do 2 until two point meet
int maxArea(vector<int> &height) {
int len = height.size();
int i = 0, j = len-1;
int res = 0, temp = 0;
while(i < j){
if(height[i] < height[j]){
temp = height[i] * (j-i);
i++;
}else{
temp = height[j] * (j-i);
j--;
}
res = max(res, temp);
}
return res;
}
本文介绍了一种求解最大面积直方图问题的有效算法。该算法通过双指针技术,从两端开始向中间逼近,逐步缩小包围区域,直至找到最大面积。适用于需要快速计算直方图最大面积的应用场景。
5820

被折叠的 条评论
为什么被折叠?



