当前位置:网站首页>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;
}
};
边栏推荐
猜你喜欢
七夕来袭——属于程序员的浪漫
leetcode-6134:找到离给定两个节点最近的节点
华为深度学习课程第九章——卷积神经网络以及案例实践
2022杭电中超杯(1)个人题解
【STM32】入门(一):环境搭建、编译、下载、运行
Image lossless compression software which works: try completely free JPG - C image batch finishing compression reduces weight tools | latest JPG batch dressing tools download
巧妙利用unbuffer实时写入
支付宝如何生成及配置公钥证书
Case practice --- Resnet classic convolutional neural network (Mindspore)
HoloView 在 jyputer lab/notebook 不显示总结
随机推荐
app 自动化 打开app (二)
扁平数组转树结构实现方式
22 Niu Ke Duo School 1 I. Chiitoitsu (Probability dp)
pytest接口自动化测试框架 | 跳过测试类
静态Pod、Pod创建流程、容器资源限制
POJ2421道路建设题解
我的创作纪念日
179. 最大数
pytest interface automation testing framework | skip test classes
Monitor the width and height of the parent element, adapt to the size of the plug-in
flink sql-client,怎么处理源端与目标增加端,sql-client包括映射表与JOB如
Leetcode - 6135: the longest part of the figure
Chapter 9 of Huawei Deep Learning Course - Convolutional Neural Network and Case Practice
gethostbyname \ getaddrinfo 解析域名IP地址不安全的原因
my creative day
拳头游戏免版权音乐下载,英雄联盟无版权音乐,可用于视频创作、直播
HoloView -- Tabular Datasets
Redis 3.2.3 crashed by signal: 11 服务宕机问题排查
Mysql数据库的部署以及初始化步骤
Case practice --- Resnet classic convolutional neural network (Mindspore)