We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 98159d7 commit 6a8a75eCopy full SHA for 6a8a75e
problems/42.trapping-rain-water.md
@@ -111,15 +111,16 @@ Python Code:
111
class Solution:
112
def trap(self, heights: List[int]) -> int:
113
n = len(heights)
114
- l, r = [0] * (n + 1), [0] * (n + 1)
+ l, r = [0] * n, [0] * n
115
ans = 0
116
- for i in range(1, len(heights) + 1):
+ for i in range(1, len(heights)):
117
l[i] = max(l[i - 1], heights[i - 1])
118
- for i in range(len(heights) - 1, 0, -1):
119
- r[i] = max(r[i + 1], heights[i])
+ for i in range(len(heights) - 2, 0, -1):
+ r[i] = max(r[i + 1], heights[i+1])
120
for i in range(len(heights)):
121
- ans += max(0, min(l[i + 1], r[i]) - heights[i])
+ ans += max(0, min(l[i], r[i]) - heights[i])
122
return ans
123
+
124
```
125
126
C++ Code:
0 commit comments