当前位置:网站首页>[brush questions] connected with rainwater (one dimension)
[brush questions] connected with rainwater (one dimension)
2022-07-03 03:56:00 【m0_ sixty million six hundred and thirty-one thousand three hun】
One 、 subject
OJ link
Given n Nonnegative integers indicate that each width is 1 Height map of columns of , Calculate columns arranged in this way , How much rain can be received after rain .
Two 、 Answer key
2.1 Ideas


2.2 Source code
public int trap(int[] height) {
if(height==null||height.length<2){
return 0;
}
int N=height.length;
int leftMax=height[0];
int rightMax=height[N-1];
int L=1;
int R=N-2;
int water=0;
while(L<=R){
if(leftMax<=rightMax){
water+=Math.max(0,leftMax-height[L]);
leftMax=Math.max(leftMax,height[L++]);
}else {
water+=Math.max(0,rightMax-height[R]);
rightMax=Math.max(rightMax,height[R--]);
}
}
return water;
}
边栏推荐
- redis在服务器linux下的启动的相关命令(安装和配置)
- 第十届中国云计算大会·中国站:展望未来十年科技走向
- Esp32 series (3): GPIO learning (take simple GPIO input and output, ADC, DAC as examples)
- leetcode:动态规划模板
- Is pytorch open source?
- Web session management security issues
- Half of 2022 is over, so we must hurry up
- JMeter starts from zero (III) -- simple use of regular expressions
- What is pytorch? Is pytorch a software?
- eth入门之DAPP
猜你喜欢

Appium自动化测试框架

Download and install node, NPM and yarn

2022 P cylinder filling examination content and P cylinder filling practice examination video
![[embedded module] OLED display module](/img/c4/474f5ee580d132654fbd1a4cd53bab.jpg)
[embedded module] OLED display module

Without sxid, suid & sgid will be in danger- Shangwen network xUP Nange

pytorch项目怎么跑?

NPM: the 'NPM' item cannot be recognized as the name of a cmdlet, function, script file, or runnable program. Please check the spelling of the name. If the path is included, make sure the path is corr

Recursion: depth first search

FileZilla Client下載安裝

2022-07-02:以下go语言代码输出什么?A:编译错误;B:Panic;C:NaN。 package main import “fmt“ func main() { var a =
随机推荐
[Blue Bridge Road -- bug free code] interpretation of some codes of matrix keyboard
Hutool动态添加定时任务
JMeter starts from zero (III) -- simple use of regular expressions
如何迈向IPv6之IPv6过渡技术-尚文网络奎哥
Numpy warning visibledeprecationwarning: creating an ndarray from ragged needed sequences
TCP, the heavyweight guest in tcp/ip model -- Kuige of Shangwen network
Makefile demo
For instruction, uploading pictures and display effect optimization of simple wechat applet development
Filter
[mathematical logic] predicate logic (predicate logic basic equivalent | eliminate quantifier equivalent | quantifier negative equivalent | quantifier scope contraction expansion equivalent | quantifi
What can learning pytorch do?
FileZilla Client下載安裝
Arlo's thinking about himself
【学习笔记】seckill-秒杀项目--(11)项目总结
Ffmpeg one / more pictures synthetic video
[Yu Yue education] reference materials of political communication science of Communication University of China
Open Visual Studio 2010 hangs when opening a SQL file sql file
Dynamic programming: longest common substring and longest common subsequence
在写web项目的时候,文件上传用到了smartupload,用了new string()进行转码,但是在数据库中,还是会出现类似扑克的乱码
node,npm以及yarn下载安装