当前位置:网站首页>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;
}
};
边栏推荐
猜你喜欢
随机推荐
Flink SQL - client, how to deal with the source side and to increase the target, the SQL - client including mapping table and the JOB such as
Leetcode - 6135: the longest part of the figure
2022杭电中超杯(1)个人题解
22 Grab the Seat 1 C.Grab the Seat (Geometry + Violence)
电磁兼容简明教程(6)测试项目
22牛客多校1 C.Grab the Seat (几何 + 暴力)
pytest接口自动化测试框架 | 单个/多个参数
Golang: go open web service
372. 超级次方
热修复技术可谓是百花齐放
pytest接口自动化测试框架 | 执行失败跳转pdb
zip打包目录所有文件(含隐藏文件/夹)
app 自动化 通过工具查看app 元素 (三)
【ASWC Arxml结构分解】-7-Explicit(显式)和Implicit(隐式) Sender-Receiver communication描述差异
Centos install php7.4, build hyperf, forward RDS
配置我的kitty
codeforces每日5题(均1600)-第二十七天
云原生FAQ
【HDLBits 刷题】Circuits(1)Combinational Logic
支付宝如何生成及配置公钥证书









