Skip to content

Commit ac7365d

Browse files
committed
Runtime: 254 ms (Top 43.79%) | Memory: 16.1 MB (Top 46.67%)
1 parent 2cee4ee commit ac7365d

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1+
# Runtime: 254 ms (Top 43.79%) | Memory: 16.1 MB (Top 46.67%)
12
class Solution:
23
def trap(self, a: List[int]) -> int:
34
l=0
45
r=len(a)-1
56
maxl=0
67
maxr=0
78
res=0
8-
9+
910
while (l<=r):
1011
if a[l]<=a[r]:
11-
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]
12+
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]
1314
l+=1
1415
else:
1516
if a[r]>=maxr: maxr=a[r]
1617
else: res+=maxr-a[r]
1718
r-=1
1819
return res
19-
20-
21-
22-

0 commit comments

Comments
 (0)