您的位置:首页 > 娱乐 > 明星 > 哈尔滨关键词优化方式_政府融资平台_seo公司优化方案_微平台推广

哈尔滨关键词优化方式_政府融资平台_seo公司优化方案_微平台推广

2025/7/13 19:52:43 来源:https://blog.csdn.net/s478527548/article/details/146556641  浏览:    关键词:哈尔滨关键词优化方式_政府融资平台_seo公司优化方案_微平台推广
哈尔滨关键词优化方式_政府融资平台_seo公司优化方案_微平台推广

很简单的困难题,和那道盛水的题目差不多,使用双指针往中间靠拢。

class Solution {
public:int trap(vector<int>& height) {int result=0;int front=0;int back=height.size()-1;int minheight=min(height[front],height[back]);while(front<back){if(height[front]<height[back]){front++;if(height[front]<minheight) result+=minheight-height[front];}else{back--;if(height[back]<minheight) result+=minheight-height[back];}minheight=max(minheight,min(height[front],height[back]));}return result;}
};

需要注意的是这个minheight只能升高不能降低。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com