classSolution{public:inttrap(vector<int>& height){int sum =0;for(int i =0; i < height.size(); i++){int rHeight = height[i];// 记录右边柱子的最高高度int lHeight = height[i];// 记录左边柱子的最高高度for(int r = i +1; r < height.size(); r++){if(height[r]> rHeight) rHeight = height[r];}for(int l = i -1; l >=0; l--){if(height[l]> lHeight) lHeight = height[l];}int h =min(lHeight, rHeight)- height[i];if(h >0) sum += h;}return sum;}};
单调栈
classSolution{public:inttrap(vector<int>& height){int result =0;stack<int> stk;stk.push(0);for(int i =1;i<height.size();i++){while(!stk.empty()&& height[i]> height[stk.top()]){int mid = stk.top();stk.pop();if(!stk.empty()){int h =min(height[stk.top()],height[i])- height[mid];int w = i - stk.top()-1;result += h*w;}}stk.push(i);}return result;}};
文章目录 首先介绍一下springboot开始正题看看lombok源码再进一步深入(下面一段是借鉴参考文章的内容)总结参考文章由于lombok基本使用在springboot框架中,因此 首先介绍一下springboot Spring Boot是一个基于Spring框架的开源Java框架,旨在简化和加速Java应用程序的开发过程。…