classSolution{public:inttrap(vector<int>& height){int ans =0;int n = height.size();if(n <=2)return ans;
stack<int> mono;for(int i =0; i < n; i++){while(!mono.empty()&& height[i]> height[mono.top()]){int mid = mono.top(); mono.pop();if(!mono.empty()){int h =min(height[mono.top()], height[i])- height[mid];int w = i - mono.top()-1;
ans += h * w;}}
mono.push(i);}return ans;}};