当前位置:网站首页>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;
}
};
边栏推荐
- [Tear AHB-APB Bridge by hand]~ Why aren't the lower two bits of the AHB address bus used to represent the address?
- C语言学习概览(二)
- pytest接口自动化测试框架 | parametrize中ids的用法
- MySQL查询进阶——从函数到表连接的使用你还记得吗
- Custom IP used in PCIE
- 最新的Cesium和Three的整合方法(附完整代码)
- LeetCode240+312+394
- 数据分析6
- ogg同步oracle到mysql,字段里面可能有需要转义的字符,怎么配置转义?
- Summary of test points about app updates in different ways
猜你喜欢
Leetcode - 6135: the longest part of the figure
Upgrade to heavyweight lock, lock reentrancy will lead to lock release?
【MySQL】操作表DML相关语句
Data Analysis 6
JVM内存模型之深究模型特征
配置我的kitty
Chapter 9 of Huawei Deep Learning Course - Convolutional Neural Network and Case Practice
Data Analysis 5
app 自动化 打开app (二)
基于MySql,Redis,Mq,ES的高可用方案解析
随机推荐
网络基础学习
Mysql数据库的部署以及初始化步骤
小程序全面屏手势配置案例
力扣周赛304 6135. 图中的最长环 内向基环树
USB Protocol (2) Terminology
Graduation thesis writing skills
【杭电多校第四场 B题】最短路图+缩点dp
Delphi MDI appliction documents maximize display, remove buttons such as maximize and minimize
七夕来袭——属于程序员的浪漫
案例实践 --- Resnet经典卷积神经网络(Mindspore)
leetcode-6134:找到离给定两个节点最近的节点
Mysql database deployment and initialization steps
The log causes these pits in the thread block, you have to prevent
【手撕AHB-APB Bridge】~ AHB地址总线的低两位为什么不用来表示地址呢?
走进音视频的世界——mp3封装格式
sqlserver 对比两张表的差异
app 自动化 通过工具查看app 元素 (三)
22牛客多校1 C.Grab the Seat (几何 + 暴力)
Golang: go open web service
配置我的kitty