当前位置:网站首页>[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;
}
边栏推荐
- FileZilla Client下载安装
- What can learning pytorch do?
- 2022年已过半,得抓紧
- [combinatorics] brief introduction to generating function (definition of generating function | Newton binomial coefficient | commonly used generating function | correlation with constant | correlation
- MySQL MAC download and installation tutorial
- 【刷题篇】多数元素(超级水王问题)
- Idea shortcut keys
- Open Visual Studio 2010 hangs when opening a SQL file sql file
- sigaction的使用
- MPLS setup experiment
猜你喜欢
Appium自动化测试框架
Application of I2C protocol of STM32F103 (read and write EEPROM)
For instruction, uploading pictures and display effect optimization of simple wechat applet development
释放数据力量的Ceph-尚文网络xUP楠哥
Download and install captura and configure ffmpeg in captura
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
【刷题篇】多数元素(超级水王问题)
Web session management security issues
js中#号的作用
The latest analysis of the main principals of hazardous chemical business units in 2022 and the simulated examination questions of the main principals of hazardous chemical business units
随机推荐
Download and install captura and configure ffmpeg in captura
@The difference between Autowired, @qualifier, @resource
Shardingsphere dynamic data source
npm : 无法将“npm”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
[mathematical logic] propositional logic (judgment of the correctness of propositional logic reasoning | formal structure is eternal truth - equivalent calculus | deduction from premise - logical reas
2022 Shandong Province safety officer C certificate examination questions and Shandong Province safety officer C certificate simulation examination question bank
Without sxid, suid & sgid will be in danger- Shangwen network xUP Nange
js中#号的作用
Nanning water leakage detection: warmly congratulate Guangxi Zhongshui on winning the first famous brand in Guangxi
递归:一维链表和数组
Mysql Mac版下载安装教程
Idea shortcut keys
Docker install and start MySQL service
pytorch怎么下载?pytorch在哪里下载?
Null and undefined
pytorch开源吗?
[Apple Photo Album push] IMessage group anchor local push
Makefile demo
Recursive use and multi-dimensional array object to one-dimensional array object
Interface embedded in golang struct