https://oj.leetcode.com/problems/trapping-rain-water/这道题使用单调队列能够O(n)时间解决。维护一个降序排列的单调队列。如果Ai>A[que.front]就说明能够使用que.front作为顶部计算一次积水。当从0-n时,须注意队列中还有元素。需...
分类:
移动开发 时间:
2014-10-14 17:22:58
阅读次数:
261
Givennnon-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.Fo...
分类:
移动开发 时间:
2014-10-11 05:30:54
阅读次数:
228
http://www.delphicorner.f9.co.uk/articles/apps7.htmTrapping Messages Sent to an ApplicationI wrote code for the OnMessage event handler of Application...
分类:
移动开发 时间:
2014-10-10 22:36:44
阅读次数:
251
解法:(1)建立一个二维数组,记录各位置左侧最高点及右侧最高点,可通过O(n)计算得到。
(2)根据上述信息及当前高度,计算该点竖直方向能容纳多少水,仍是O(n)完成。
综上,渐近时间复杂度为O(n);
class Solution {
public:
int trap(int A[], int n) {
if(n
return 0;
int* hi...
分类:
移动开发 时间:
2014-10-07 15:57:53
阅读次数:
181
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
For example,
Given [0,1,0,2,1,0,1,3,2,1,2,1]...
分类:
移动开发 时间:
2014-09-23 16:46:54
阅读次数:
224
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
For example,
Given [0,1,0,2,1,0,1,3,2,1,2,1]...
分类:
移动开发 时间:
2014-09-13 21:34:25
阅读次数:
219
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining....
分类:
移动开发 时间:
2014-09-01 21:01:33
阅读次数:
220
本文为senlie原创,转载请保留此地址:http://blog.csdn.net/zhengsenlie
Trapping Rain Water
Total Accepted: 14568 Total
Submissions: 50810My Submissions
Given n non-negative integers representin...
分类:
移动开发 时间:
2014-08-29 01:24:36
阅读次数:
238
Container With Most Water
Given n non-negative integers a1, a2,
..., an, where each represents a point at coordinate (i, ai). n vertical
lines are drawn such that the two endpoints of line...
分类:
移动开发 时间:
2014-08-22 16:17:59
阅读次数:
208
Givennnon-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining. 1...
分类:
移动开发 时间:
2014-08-10 01:34:09
阅读次数:
375