LeetCode:7.接雨水
目录
1.接雨水
1.接雨水
class Solution {
public:int trap(vector<int>& height) {int area = 0;int left = 0, right = height.size() - 1;int maxleft = 0, maxright = 0;while(left < right){maxleft = max(maxleft, height[left]);maxright = max(maxright, height[right]);if(height[left] < height[right]){area += maxleft - height[left];++left;}else{area += maxright - height[right];--right;}}return area;}
};