Nav: << previous: 41.缺失的第一个正数 | next: 43.字符串相乘 >>
Description
tab: English
<p>Given <code>n</code> non-negative integers representing an elevation map where the width of each bar is <code>1</code>, compute how much water it can trap after raining.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<img src="https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png" style="width: 412px; height: 161px;" />
<pre>
<strong>Input:</strong> height = [0,1,0,2,1,0,1,3,2,1,2,1]
<strong>Output:</strong> 6
<strong>Explanation:</strong> The above elevation map (black section) 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.
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong> height = [4,2,0,3,2,5]
<strong>Output:</strong> 9
</pre>
<p> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == height.length</code></li>
<li><code>1 <= n <= 2 * 10<sup>4</sup></code></li>
<li><code>0 <= height[i] <= 10<sup>5</sup></code></li>
</ul>
---
[submissions](https://leetcode.com/problems/trapping-rain-water/submissions/) | [solutions](https://leetcode.com/problems/trapping-rain-water/solutions/)
tab: 中文
<p>给定 <code>n</code> 个非负整数表示每个宽度为 <code>1</code> 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水。</p>
<p> </p>
<p><strong>示例 1:</strong></p>
<p><img src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2018/10/22/rainwatertrap.png" style="height: 161px; width: 412px;" /></p>
<pre>
<strong>输入:</strong>height = [0,1,0,2,1,0,1,3,2,1,2,1]
<strong>输出:</strong>6
<strong>解释:</strong>上面是由数组 [0,1,0,2,1,0,1,3,2,1,2,1] 表示的高度图,在这种情况下,可以接 6 个单位的雨水(蓝色部分表示雨水)。
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入:</strong>height = [4,2,0,3,2,5]
<strong>输出:</strong>9
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == height.length</code></li>
<li><code>1 <= n <= 2 * 10<sup>4</sup></code></li>
<li><code>0 <= height[i] <= 10<sup>5</sup></code></li>
</ul>
---
[提交记录](https://leetcode.cn/problems/trapping-rain-water/submissions/) | [题解](https://leetcode.cn/problems/trapping-rain-water/solution/)
Solutions & Notes
properties:
note.updated:
displayName: Last Updated
note.relative_links:
displayName: Related Links
note.desc:
displayName: Description
note.grade:
displayName: Rating
note.program_language:
displayName: Language
note.time_complexity:
displayName: TC
note.space_complexity:
displayName: SC
views:
- type: table
name: Solutions & Notes
filters:
and:
- file.hasLink(this.file)
- file.tags.containsAny("leetcode/solution", "leetcode/note")
order:
- file.name
- desc
- program_language
- time_complexity
- space_complexity
- grade
- relative_links
- updated
sort:
- property: grade
direction: ASC
- property: time_complexity
direction: ASC
- property: program_language
direction: ASC
columnSize:
file.name: 104
note.space_complexity: 65
note.grade: 126
Similar Problems
properties:
note.lcTopics:
displayName: Topics
note.lcAcRate:
displayName: AC Rate
note.favorites:
displayName: Favorites
note.grade:
displayName: Rating
note.translatedTitle:
displayName: Title (CN)
note.lcDifficulty:
displayName: Difficulty
views:
- type: table
name: Similar Problems
filters:
and:
- file.hasLink(this.file)
- similarQuestions.contains(this.file)
order:
- file.name
- translatedTitle
- lcTopics
- lcDifficulty
- lcAcRate
- grade
- favorites
sort:
- property: file.name
direction: ASC
- property: lcTopics
direction: DESC
columnSize:
note.translatedTitle: 240
note.lcTopics: 347
note.lcAcRate: 75
note.grade: 122