当前位置:网站首页>leetcode 42. Catch the rain
leetcode 42. Catch the rain
2022-08-01 08:16: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;
}
};
边栏推荐
猜你喜欢
Fist game copyright-free music download, League of Legends copyright-free music, can be used for video creation, live broadcast
Microsoft Azure & NVIDIA IoT developers season I | Azure IoT & NVIDIA Jetson development foundation
VoLTE基础学习系列 | 什么是SIP和IMS中的Forking
leetcode-6135:图中的最长环
七夕来袭——属于程序员的浪漫
【HDLBits 刷题】Circuits(1)Combinational Logic
VSCode 快捷键及通用插件推荐
[Tear AHB-APB Bridge by hand]~ Why aren't the lower two bits of the AHB address bus used to represent the address?
LeetCode 415:字符串相加
leetcode-6132: Make all elements in array equal to zero
随机推荐
MySQL query advanced - from the use of functions to table joins, do you remember?
HoloView -- Tabular Datasets
【MySQL】操作表DML相关语句
【Unity3D】相机
网络基础学习
Pod环境变量和initContainer
优炫数据库支持Oracle哪几种时间及日期类型
Prime Ring Problem(素数环问题)
sqlserver 对比两张表的差异
我的创作纪念日
The log causes these pits in the thread block, you have to prevent
最新的Cesium和Three的整合方法(附完整代码)
22牛客多校1 C.Grab the Seat (几何 + 暴力)
Fist game copyright-free music download, League of Legends copyright-free music, can be used for video creation, live broadcast
Redis学习
HPC系统简介
LabVIEW中局部变量和全局变量的分配
Leetcode - 6135: the longest part of the figure
Golang: go static file processing
Electromagnetic compatibility introductory tutorial (6) test project