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, ...
随机推荐
- [AYUI]QQ管家源码已经开源
(0-50元 黑色字体 享受AY 1周的 ayui 技术问答) (50-100元 绿色字体 享受AY 15天的 ayui 技术问答) (100-150元 蓝色字体 享受AY 20天的 ayui ...
- Android--Matrix图片变换处理
前言 本篇博客主要讲解一下如何处理对一个Bitmap对象进行处理,包括:缩放.旋转.位移.倾斜等.在最后将以一个简单的Demo来演示图片特效的变换. 本篇博客的主要内容: Matrix Matrix缩 ...
- css强制换行和超出隐藏实现
一.强制换行1 word-break: break-all; 只对英文起作用,以字母作为换行依据. 2 word-wrap: break-word; 只对英文起作用,以单词作为换行依据. 3 ...
- windbg----as、$u0(固定别名、自定义别名)
固定别名($u0~$u9) 有10个固定别名.他们是$u0, $u1, ..., $u9.他们的等价字符串可以是不包含ENTER键的任意字符串.使用r (Registers)命令为固定别明指定等价字符 ...
- CSV - 操作比较
在数据报表生成的时候,我们一般会用程序去生成CSV.其中有些需要注意的地方. log_file = open('delay.%s.csv' % s_end, 'w') log_file.write(' ...
- 【原创】从零开始学SpagoBI5.X源码汉化编译
从零开始学SpagoBI5.X源码汉化编译 一.新建Tomact Server 服务器并配置测试1.文件-新建-其他-过滤server-服务类型选择Tomact V7.0 Server2.根据需要修改 ...
- C#排序比较
与C#定义了相等性比较规范一样,C#也定义了排序比较规范,以确定一个对象与另一个对象的先后顺序.排序规范如下 IComparable接口(包括IComparable接口和IComparable< ...
- 我爱免费之FreeFileSync文件夹同步软件
因为项目需求用到FreeFileSync文件夹同步软件,这个软件好在免费.易用.功能强,我真的是大爱这种软件.http://freefilesync.com/ 可以下载免费软件,有需要的朋友,大可以一 ...
- Java与邮件系统交互之使用Socket验证邮箱是否存在
最近遇到一个需求:需要验证用户填写的邮箱地址是否真实存在,是否可达.和普通的正则表达式不同,他要求尝试链接目标邮箱服务器并请求校验目标邮箱是否存在. 先来了解 DNS之MX记录 对于DNS不了解的,请 ...
- 聊聊并发(七)——Java中的阻塞队列
3. 阻塞队列的实现原理 聊聊并发(七)--Java中的阻塞队列 作者 方腾飞 发布于 2013年12月18日 | ArchSummit全球架构师峰会(北京站)2016年12月02-03日举办,了解更 ...