forked from codedecks-in/LeetCode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trapping_rain.py
34 lines (29 loc) · 942 Bytes
/
trapping_rain.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Solution:
def trap(self, height: List[int]) -> int:
water=0
left=-1
right=len(height)
current=0
arr1=[]
arr2=[]
left_max=0
right_max=0
for current in range(len(height)):
while(left!=current):
left+=1
if(left_max<=height[left]):
left_max=height[left]
arr1.append(left_max)
while(right!=current):
right-=1
if(right_max<=height[right]):
right_max=height[right]
arr2.append(right_max)
right_max=0
right=len(height)
left=-1
for i in range(len(arr1)):
s=min(arr1[i],arr2[i])-height[i];
if(s>0):
water+=s
return water