1
class Solution {
2
public int trap(int[] height) {
3
int left = 0;
4
int right = height.length - 1;
5

6
int l_max = height[left];
7
int r_max = height[right];
8
int res = 0;
9

10
while (left < right) {
11
if (l_max < r_max) {
12
left += 1;
13
l_max = Math.max(l_max, height[left]);
14
res += l_max - height[left];
15
} else {
16
right -= 1;
17
r_max = Math.max(r_max, height[right]);
18
res += r_max - height[right];
19
}
20
}
21

22
return res;
23
}
24
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0