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 rain water (blue section) are being trapped. Thanks Marcos for contributing this image! 思路: 这一道题类似于leetcode 11
Problem: 根据所给数组的值,按照上图的示意图。求解积水最大体积。 首先对所给数组进行遍历操作,求出最大高度所对应的下标为maxIndex 之后从左向右进行遍历,设置左边高度为leftMax 并初始化为 height[0],从i==1到i==maxIndex进行遍历。不断更新water,以及leftMax 当height[I]小于leftMax时,water += leftMax...
https://leetcode-cn.com/problems/trapping-rain-water/ 题目内容 给定n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水。 示例: 输入: [0,1,0,2,1,0,1,3,2,1,2,1] 输出: 6 思路 我们可以设置两个数组,「left_height_array」和「right_height_array」; 其...
今天和大家聊的问题叫做 接雨水 II,我们先来看题面:leetcode-cn.com/problem Given an m x n integer matrix heightMap representing the height of each unit cell in a 2D elevation map, return the volume of water it can trap after raining. 给你一个 m x n 的矩阵,其中的值均为非负整数,代表...
LeetCode42 Trapping Rain Water this problem is really classic and we have a really classic way to solve this problem: we iterate every value of given array, and each time, for a fixed value, we only consider the water it can contained, and we maintained two variables: leftMax and right...
Here are some other questions that do not fit in other categories. We recommend: Trapping Rain Water and The Skyline Problem. If you'd like more challenge, we highly recommend you to solve the last two problems: The Skyline Problem and Largest Rectangle in Histogram. Both problems are very...
My LeetCode Daily Problem & Contest Group: See rules and score board here (If you are interested in joining this group, ping me guan.huifeng@gmail.com) LeetCode难题代码和算法要点分析 目前分类目录 Two Pointers 011.Container-With-Most-Water (M+) 015.3Sum (M) 016.3Sum-Closet (M) 018.4Sum...
CompileC++files using command: g++ -std=c++11 -Wall src/bar.cpp -o bar OR You can build all the files usingmake(Use MinGW GCC and GNU Make on Windows). The☢means that you need to have a LeetCode Premium Subscription. ProblemSolution ...
042 Trapping rain water: another tapping water related problem. last problem is the bucket without thickness, but this problem the number of waters it can contains. and this time we still using double direction pointers. but we maintained two other variables, leftMax and rightMax ...
Section 1: Microsoft Array Question: Container with most water (Medium) Lecture 1 Introduction to the problem Lecture 2 Brute Force solution Intuition Lecture 3 pseudocode walkthrough Lecture 4 Better Approach intuition Lecture 5 Approach 2 Pseudocode walkthrough Lecture 6 Implementing the code Section...