LeetCode - 42. Trapping Rain Water
42. Trapping Rain Water
Problem's Link
----------------------------------------------------------------------------
Mean:
在坐标上给你一些竖直放置的条形积木,问你这个积木能够容纳多少液体.
analyse:
首先找出最高的积木,然后从前往后一直扫到最高积木,从后往前一直扫到最高积木,两部分体积相加即可.
Time complexity: O(N)
view code
;
;;
;
);
;
;
);;
}
/*
*/
2.方法二:时间O(n),空间(1)
;
;
while(left<right)
{
if(height[left]<=height[right])
{
if(height[left]>maxLeft)
maxLeft=height[left];
res+=maxLeft-height[left];
left++;
}
else
{
if(height[right]>maxRight)
maxRight=height[right];
res+=maxRight-height[right];
right--;
}
}
return res;
}
};
LeetCode - 42. Trapping Rain Water的更多相关文章
- leetcode#42 Trapping rain water的五种解法详解
leetcode#42 Trapping rain water 这道题十分有意思,可以用很多方法做出来,每种方法的思想都值得让人细细体会. 42. Trapping Rain WaterGiven n ...
- [array] leetcode - 42. Trapping Rain Water - Hard
leetcode - 42. Trapping Rain Water - Hard descrition Given n non-negative integers representing an e ...
- LeetCode 42. Trapping Rain Water 【两种解法】(python排序遍历,C++ STL map存索引,时间复杂度O(nlogn))
LeetCode 42. Trapping Rain Water Python解法 解题思路: 本思路需找到最高点左右遍历,时间复杂度O(nlogn),以下为向左遍历的过程. 将每一个点的高度和索引存 ...
- [LeetCode] 42. Trapping Rain Water 收集雨水
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...
- leetCode 42.Trapping Rain Water(凹槽的雨水) 解题思路和方法
Trapping Rain Water Given n non-negative integers representing an elevation map where the width of e ...
- [LeetCode] 42. Trapping Rain Water 解题思路
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...
- [leetcode]42. Trapping Rain Water雨水积水问题
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...
- LeetCode 42 Trapping Rain Water(积水体积)
题目链接: https://leetcode.com/problems/trapping-rain-water/?tab=Description Problem: 根据所给数组的值,按照上图的示意 ...
- Java [Leetcode 42]Trapping Rain Water
题目描述: Given n non-negative integers representing an elevation map where the width of each bar is 1, ...
随机推荐
- 使用MySQL Migration Toolkit快速将Oracle数据导入MySQL[转]
使用MySQL Migration Toolkit快速将Oracle数据导入MySQL上来先说点废话本人最近在学习一些数据库方面的知识,之前接触过Oracle和MySQL,最近又很流行MongoDB非 ...
- eclipse android logcat 只显示自己应用程序信息的设置方法
1 elcipse 中往往会在logcat中显示 all message ,而这里面的信息太多,根本没有办法进行区分.如图: 2 我们想显示自己项目的 logcat .下面开始设置. 3 首先点击上面 ...
- crontab使用方法和示例
crond是linux中的一个定时任务常驻程序,它会在每分钟检查一次作业列表,从而达到在指定时间自动运行指定的作业,这个程序对于系统运维来讲必不可少. 通常我们使用crontab程序来设定和管理作业的 ...
- mac上使用生成RSA公钥和密钥
关于RSA加密解密的问题,没事弄了一下,先把主要的流程保存下来,以备交流或者以后用. 首先确保你的电脑上安装了openssl,一般mac系统安装后都会自动安装!怎么安装??.....请百度...... ...
- Linux 统计某个字符串出现的次数
要统计一个字符串出现的次数,这里现提供自己常用两种方法: 1. 使用vim统计 用vim打开目标文件,在命令模式下,输入 :%s/objStr//gn 即可 2. 使用grep: grep -o ob ...
- (转)Python rsa 签名与验证 sign and verify
转自:http://wawehi.blog.163.com/blog/static/143780306201371361120515/ 网上一搜一大把的 python rsa 相关的东西,python ...
- Asp.net Core WebApi 使用Swagger做帮助文档,并且自定义Swagger的UI
WebApi写好之后,在线帮助文档以及能够在线调试的工具是专业化的表现,而Swagger毫无疑问是做Docs的最佳工具,自动生成每个Controller的接口说明,自动将参数解析成json,并且能够在 ...
- 提高 Android 代码质量的4个工具
在这篇文章中,我将通过不同的自动化工具如CheckStyle,FindBugs,PMD以及Android Lint来介绍(如何)提高你的安卓代码质量.通过自动化的方式检查你的代码非常有用,尤其当你在一 ...
- android studio 中查找代码中的硬编码
在Android Studio中同时按下Ctrl + Shift+ F 或者其他自定义的快捷键,打开全局搜索,在全局搜索中输入 ^((?!(\*|//)).)+[\u4e00-\u9fa5] 并打勾 ...
- HDU 1175 连连看
连连看 Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...