parent
bf2a4581b2
commit
7b263b445d
|
|
@ -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
|
||||||
|
```
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue