|
| int | trap (vector< int > &height) |
| |
Definition at line 6 of file main.cpp.
◆ trap()
| int Solution::trap |
( |
vector< int > & |
height | ) |
|
|
inline |
Definition at line 9 of file main.cpp.
10 {
11 int total_volume = 0;
12 int left = 0;
13 int right = height.size() - 1;
14 int left_max = 0;
15 int right_max = 0;
16
17
18 while (left <= right)
19 {
20 if (height[left] <= height[right])
21 {
22 if (height[left] >= left_max)
23 left_max = height[left];
24 else
25 total_volume += left_max - height[left];
26 left++;
27 }
28 else
29 {
30 if (height[right] >= right_max)
31 right_max = height[right];
32 else
33 total_volume += right_max - height[right];
34 right--;
35 }
36 }
37 return total_volume;
38 }
Referenced by main().
The documentation for this class was generated from the following file: