*42. Trapping Rain Water 接雨水】的更多相关文章

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. The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of…
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力求解 保存左右最大值 单调栈 日期 题目地址:https://leetcode-cn.com/problems/string-to-integer-atoi/ 题目描述 Given n non-negative integers representing an elevation map where the width of each bar is…
1. 原始题目 给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水. 上面是由数组 [0,1,0,2,1,0,1,3,2,1,2,1] 表示的高度图,在这种情况下,可以接 6 个单位的雨水(蓝色部分表示雨水). 感谢 Marcos 贡献此图. 示例: 输入: [0,1,0,2,1,0,1,3,2,1,2,1] 输出: 6 2. 思路 最简单的想法:对于每个元素都要考虑它能接多少雨水: 第一个元素是0,能接0雨水 第二个元素是1,能接0雨水 第三个元素…
一.题目说明 题目是42. Trapping Rain Water,翻译起来就是"接雨水".给n个非负正数代表高度,每个正数宽度为1,让计算能多少雨水.题目难度是Hard 二.我的解法 这个题目是找"坑",然后计算里面可以存的"雨".总共提交了5次,前面几次都是边界错误. 代码如下: #include<iostream> #include<vector> using namespace std; class Solutio…
42. Trapping Rain Water Problem's Link ---------------------------------------------------------------------------- Mean: 在坐标上给你一些竖直放置的条形积木,问你这个积木能够容纳多少液体. analyse: 首先找出最高的积木,然后从前往后一直扫到最高积木,从后往前一直扫到最高积木,两部分体积相加即可. Time complexity: O(N) view code ;  …
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 42: Trapping Rain Waterhttps://oj.leetcode.com/problems/trapping-rain-water/ Given n non-negative integers representing an elevation map where the width of each bar is 1,compute how much wa…
leetcode#42 Trapping rain water 这道题十分有意思,可以用很多方法做出来,每种方法的思想都值得让人细细体会. 42. Trapping Rain WaterGiven 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 ex…
leetcode - 42. Trapping Rain Water - Hard descrition 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],…
LeetCode 42. Trapping Rain Water Python解法 解题思路: 本思路需找到最高点左右遍历,时间复杂度O(nlogn),以下为向左遍历的过程. 将每一个点的高度和索引存成一个元组 (val, idx) 找到最高的点(可能有多个,任取一个),记为 (now_val, now_idx). 向左找第一个val不大于now_val的点(left_val, left_idx). 以left_val作为水平面,用height[left_val+1, now_val-1]中每一…
11. Container With Most Water https://www.cnblogs.com/grandyang/p/4455109.html 用双指针向中间滑动,较小的高度就作为当前情况的高度,然后循环找容量的最大值. 不管两个指针中间有多少高度的柱子,只管两头,因为两头的才决定最大容量. class Solution { public: int maxArea(vector<int>& height) { if(height.empty()) ; ; ,end = h…