MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / trap

Method trap

Python/trapping_rain.py:2–34  ·  view source on GitHub ↗
(self, height: List[int])

Source from the content-addressed store, hash-verified

1class Solution:
2 def trap(self, height: List[int]) -> int:
3 water=0
4 left=-1
5 right=len(height)
6 current=0
7 arr1=[]
8 arr2=[]
9 left_max=0
10 right_max=0
11 for current in range(len(height)):
12 while(left!=current):
13 left+=1
14 if(left_max<=height[left]):
15 left_max=height[left]
16 arr1.append(left_max)
17 while(right!=current):
18 right-=1
19
20 if(right_max<=height[right]):
21 right_max=height[right]
22 arr2.append(right_max)
23 right_max=0
24
25 right=len(height)
26 left=-1
27
28
29 for i in range(len(arr1)):
30 s=min(arr1[i],arr2[i])-height[i];
31 if(s>0):
32 water+=s
33
34 return water

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected