We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2cee4ee commit ac7365dCopy full SHA for ac7365d
scripts/algorithms/T/Trapping Rain Water/Trapping Rain Water.py
@@ -1,22 +1,19 @@
1
+# Runtime: 254 ms (Top 43.79%) | Memory: 16.1 MB (Top 46.67%)
2
class Solution:
3
def trap(self, a: List[int]) -> int:
4
l=0
5
r=len(a)-1
6
maxl=0
7
maxr=0
8
res=0
-
9
+
10
while (l<=r):
11
if a[l]<=a[r]:
- if a[l]>=maxl: maxl=a[l] #update maxl if a[l] is >=
12
- else: res+=maxl-a[l] #adding captured water when maxl>a[l]
+ if a[l]>=maxl: maxl=a[l] #update maxl if a[l] is >=
13
+ else: res+=maxl-a[l] #adding captured water when maxl>a[l]
14
l+=1
15
else:
16
if a[r]>=maxr: maxr=a[r]
17
else: res+=maxr-a[r]
18
r-=1
19
return res
20
21
22
0 commit comments