当前位置:网站首页>leetcode 42. 接雨水
leetcode 42. 接雨水
2022-08-01 08:00:00 【henujolly】
class Solution {
public:
int trap(vector<int>& height) {
vector<int>left(height.size()+1);
vector<int>right(height.size()+1);
left[0] = height[0];
for(int i=1;i<height.size();i++){
left[i]=max(left[i-1],height[i]);
}
right[height.size()-1]=height[height.size()-1];
for(int i=height.size()-2;i>=0;i--){
right[i]=max(right[i+1],height[i]);
}
int sum=0;
for(int i=0;i<height.size();i++){
sum+=min(left[i],right[i])-height[i];
}
return sum;
}
};
边栏推荐
猜你喜欢
随机推荐
Golang:go静态文件处理
The log causes these pits in the thread block, you have to prevent
How to use Photoshop to composite star trail photos, post-processing method of night sky star trail photos
pytest接口自动化测试框架 | 使用函数返回值的形式传入参数值
Chapters 6 and 7 of Huawei Deep Learning Course
pytest接口自动化测试框架 | 集成Allure测试报告
走进音视频的世界——mp3封装格式
力扣每日一题-第44天-290. 单词规律
数据分析6
leetcode-6133:分组的最大数量
179. 最大数
22牛客多校1 J.Serval and Essay (启发式合并)
flink sql-client,怎么处理源端与目标增加端,sql-client包括映射表与JOB如
my creative day
mysql查看cpu使用情况
C语言中编译时出现警告C4013(C语言不加函数原型产生的潜在错误)
Delphi MDI appliction 文档最大化显示、去掉最大化最小化等按钮
升级为重量级锁,锁重入会导致锁释放?
案例实践 --- Resnet经典卷积神经网络(Mindspore)
HoloView -- Tabular Datasets









