当前位置:网站首页>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;
}
};
边栏推荐
- The log causes these pits in the thread block, you have to prevent
- 拳头游戏免版权音乐下载,英雄联盟无版权音乐,可用于视频创作、直播
- 日志导致线程Block的这些坑,你不得不防
- The use of Golang: go template engine
- Image lossless compression software which works: try completely free JPG - C image batch finishing compression reduces weight tools | latest JPG batch dressing tools download
- navicat mysql 内存占用过高,被强制关闭
- Shell executes SQL to send emails
- Redis 3.2.3 crashed by signal: 11 服务宕机问题排查
- Summary of test points about app updates in different ways
- HoloView -- Tabular Datasets
猜你喜欢
C语言中编译时出现警告C4013(C语言不加函数原型产生的潜在错误)
USB Protocol (2) Terminology
app 自动化 通过工具查看app 元素 (三)
小程序更多的手势事件(左右滑动、放大缩小、双击、长按)
How to use Photoshop to composite star trail photos, post-processing method of night sky star trail photos
SaaS安全认证综合指南
What do the values 1, 2, and 3 in nodetype mean?
【Unity3D】相机
VoLTE基础学习系列 | 企业语音网简述
Golang:go获取url和表单属性值
随机推荐
热修复技术可谓是百花齐放
Golang: go get url and form attribute value
最新的Cesium和Three的整合方法(附完整代码)
Go supports OOP: use struct instead of class
C语言学习概览(三)
Case practice --- Resnet classic convolutional neural network (Mindspore)
日志导致线程Block的这些坑,你不得不防
USB 协议 (二) 术语
372. 超级次方
flink sql-client,怎么处理源端与目标增加端,sql-client包括映射表与JOB如
【ASWC Arxml结构分解】-7-Explicit(显式)和Implicit(隐式) Sender-Receiver communication描述差异
正则表达式符号
根据指定区域内容生成图片并进行分享总结
pytest接口自动化测试框架 | 单个/多个参数
Monitor the width and height of the parent element, adapt to the size of the plug-in
Delphi MDI appliction documents maximize display, remove buttons such as maximize and minimize
走进音视频的世界——mp3封装格式
Chapter 9 of Huawei Deep Learning Course - Convolutional Neural Network and Case Practice
微信小程序请求封装
The use of Golang: go template engine