Skip to content

Commit cddb60b

Browse files
authored
Update 042._trapping_rain_water.md
1 parent ef638a4 commit cddb60b

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

docs/Leetcode_Solutions/Python/042._trapping_rain_water.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
1-
### 42. Trapping Rain Water
1+
# 42. Trapping Rain Water
22

3+
**<font color=red>难度: Hard</font>**
34

5+
## 刷题内容
46

5-
题目:
6-
<https://leetcode.com/problems/trapping-rain-water/>
7+
> 原题连接
78
9+
* https://leetcode.com/problems/trapping-rain-water/description/
810

9-
难度:
10-
Hard
11+
> 内容描述
1112
12-
思路:
13+
```
14+
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.
15+
```
16+
17+
![](https://github.com/apachecn/awesome-algorithm/blob/master/images/042/rainwatertrap.png)
18+
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!
19+
```
20+
Example:
21+
22+
Input: [0,1,0,2,1,0,1,3,2,1,2,1]
23+
Output: 6
24+
```
25+
26+
## 解题方案
27+
28+
> 思路 1
29+
******- 时间复杂度: O(N)******- 空间复杂度: O(1)******
1330

1431
题目有几个特性可用,bar width = 1,然后第一个和最后一个是不能trap water,其次中间的部分能trap多少水是看`左右高度差较低的那个 - 本身的高度`
1532

@@ -35,5 +52,4 @@ class Solution(object):
3552
water += min_height - height[r]
3653
r -= 1
3754
return water
38-
3955
```

0 commit comments

Comments
 (0)