mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
添加 0042接雨水 python3版本 双指针法
添加 0042接雨水 python3版本 双指针法
This commit is contained in:
@ -354,4 +354,24 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
## 其他语言版本
|
## 其他语言版本
|
||||||
|
python 版本
|
||||||
|
双指针法
|
||||||
|
```python3
|
||||||
|
class Solution:
|
||||||
|
def trap(self, height: List[int]) -> int:
|
||||||
|
res = 0
|
||||||
|
for i in range(len(height)):
|
||||||
|
if i == 0 or i == len(height)-1: continue
|
||||||
|
lHight = height[i-1]
|
||||||
|
rHight = height[i+1]
|
||||||
|
for j in range(i-1):
|
||||||
|
if height[j] > lHight:
|
||||||
|
lHight = height[j]
|
||||||
|
for k in range(i+2,len(height)):
|
||||||
|
if height[k] > rHight:
|
||||||
|
rHight = height[k]
|
||||||
|
res1 = min(lHight,rHight) - height[i]
|
||||||
|
if res1 > 0:
|
||||||
|
res += res1
|
||||||
|
return res
|
||||||
|
```
|
||||||
|
Reference in New Issue
Block a user