-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
class Solution {
public:
int trap(vector<int>& height) {
int left = 0;
int right = height.size() - 1;
int left_max = height[left];
int right_max = height[right];
int water = 0;
while (left < right) {
if (height[left] < height[right]) {
if (height[left] >= left_max) {
left_max = height[left];
} else {
water += left_max - height[left];
}
left++;
} else {
if (height[right] >= right_max) {
right_max = height[right];
} else {
water += right_max - height[right];
}
right--;
}
}
return water;
}
};Metadata
Metadata
Assignees
Labels
Projects
Status
Done