class Solution {
public:inttrap(vector<int>& height){int h =0;int result =0;
stack<int> st;//存index// st.push(0);for(int i =0; i < height.size(); i++){if(!st.empty()&& height[st.top()]<= height[i]){while(!st.empty()&& height[st.top()]< height[i]){
h = height[st.top()];
st.pop();if(!st.empty()){int w = i-st.top()-1;int h2 =min(height[st.top()], height[i])-h;
result += h2 * w;}}}
st.push(i);}return result;}};