当前位置: 首页 > news >正文

怎么找到网站的空间服务商快速seo整站优化排行

怎么找到网站的空间服务商,快速seo整站优化排行,ui设计师有前途吗,手机端网站制作教程单调栈 单调栈通过维护数据的单调性,将原本O(n)的暴力解法优化到O(n),是解决一系列区间极值问题的利器。掌握单调栈的关键在于理解问题本质并选择合适的单调性方向。 使用技巧 确定单调性:根据问题需求选择递增栈还是递减栈 找下一个更大元素…

单调栈

单调栈通过维护数据的单调性,将原本O(n²)的暴力解法优化到O(n),是解决一系列区间极值问题的利器。掌握单调栈的关键在于理解问题本质并选择合适的单调性方向。

使用技巧

  1. 确定单调性:根据问题需求选择递增栈还是递减栈

    • 找下一个更大元素 → 单调递减栈

    • 找下一个更小元素 → 单调递增栈

  2. 存储内容:根据问题决定栈内存储元素值还是索引

    • 需要计算宽度 → 存储索引

    • 只需要比较值 → 存储值

  3. 边界处理:考虑数组边界情况,可添加哨兵元素简化逻辑

  4. 多步操作:有时需要先从左到右扫描,再从右到左扫描

基本概念

1. 单调栈特性

  • 单调递增栈:栈内元素从栈底到栈顶保持递增顺序

  • 单调递减栈:栈内元素从栈底到栈顶保持递减顺序

2. 常见应用场景

  • 寻找下一个更大/更小元素

  • 计算柱状图中的最大矩形

  • 解决接雨水问题

  • 股票跨度问题

 算法实现

//单调递增栈vector<int> nextGreaterElement(vector<int>& nums) {int n = nums.size();vector<int> res(n, -1);stack<int> st; // 存储的是元素下标for (int i = 0; i < n; i++) {while (!st.empty() && nums[st.top()] < nums[i]) {res[st.top()] = nums[i]; // 当前元素是栈顶元素的下一个更大元素st.pop();}st.push(i);}return res;
}
//单调递减栈vector<int> nextSmallerElement(vector<int>& nums) {int n = nums.size();vector<int> res(n, -1);stack<int> st;for (int i = 0; i < n; i++) {while (!st.empty() && nums[st.top()] > nums[i]) {res[st.top()] = nums[i]; // 当前元素是栈顶元素的下一个更小元素st.pop();}st.push(i);}return res;
}

经典应用

//下一个更大元素  (LeetCode 496)
vector<int> nextGreaterElement(vector<int>& nums1, vector<int>& nums2) {stack<int> st;unordered_map<int, int> nextGreater;for (int num : nums2) {while (!st.empty() && st.top() < num) {nextGreater[st.top()] = num;st.pop();}st.push(num);}vector<int> res;for (int num : nums1) {res.push_back(nextGreater.count(num) ? nextGreater[num] : -1);}return res;
}

 

//柱状图中的最大矩形 (LeetCode 84)int largestRectangleArea(vector<int>& heights) {stack<int> st;heights.push_back(0); // 添加哨兵int maxArea = 0;for (int i = 0; i < heights.size(); i++) {while (!st.empty() && heights[st.top()] > heights[i]) {int h = heights[st.top()];st.pop();int w = st.empty() ? i : i - st.top() - 1;maxArea = max(maxArea, h * w);}st.push(i);}return maxArea;
}
//接雨水 (LeetCode 42)int trap(vector<int>& height) {stack<int> st;int water = 0;for (int i = 0; i < height.size(); i++) {while (!st.empty() && height[st.top()] < height[i]) {int bottom = height[st.top()];st.pop();if (st.empty()) break;int left = st.top();int h = min(height[left], height[i]) - bottom;int w = i - left - 1;water += h * w;}st.push(i);}return water;
}
//股票跨度问题 (LeetCode 901)class StockSpanner {stack<pair<int, int>> st; // {price, span}public:StockSpanner() {}int next(int price) {int span = 1;while (!st.empty() && st.top().first <= price) {span += st.top().second;st.pop();}st.push({price, span});return span;}
};
//每日温度 (LeetCode 739)
vector<int> dailyTemperatures(vector<int>& T) {int n = T.size();vector<int> res(n, 0);stack<int> st;for (int i = 0; i < n; i++) {while (!st.empty() && T[st.top()] < T[i]) {res[st.top()] = i - st.top();st.pop();}st.push(i);}return res;
}

 


文章转载自:
http://apocryphal.rwzc.cn
http://indulge.rwzc.cn
http://incomprehension.rwzc.cn
http://abrazo.rwzc.cn
http://egg.rwzc.cn
http://weather.rwzc.cn
http://tarre.rwzc.cn
http://multinest.rwzc.cn
http://leishmanial.rwzc.cn
http://australian.rwzc.cn
http://luteotropin.rwzc.cn
http://ironmongery.rwzc.cn
http://flowerbed.rwzc.cn
http://unrequited.rwzc.cn
http://isochrony.rwzc.cn
http://pvc.rwzc.cn
http://geranium.rwzc.cn
http://chipewyan.rwzc.cn
http://panbroil.rwzc.cn
http://daytale.rwzc.cn
http://whoopee.rwzc.cn
http://miserable.rwzc.cn
http://spectrophotoelectric.rwzc.cn
http://manners.rwzc.cn
http://forget.rwzc.cn
http://torous.rwzc.cn
http://sportsman.rwzc.cn
http://xograph.rwzc.cn
http://prosaism.rwzc.cn
http://rowel.rwzc.cn
http://ret.rwzc.cn
http://grotesque.rwzc.cn
http://tokushima.rwzc.cn
http://intermezzo.rwzc.cn
http://pruine.rwzc.cn
http://sandal.rwzc.cn
http://bickiron.rwzc.cn
http://caravansary.rwzc.cn
http://daube.rwzc.cn
http://extensionless.rwzc.cn
http://secret.rwzc.cn
http://chawl.rwzc.cn
http://plowboy.rwzc.cn
http://pakchoi.rwzc.cn
http://tithable.rwzc.cn
http://peninsular.rwzc.cn
http://unscratched.rwzc.cn
http://bonn.rwzc.cn
http://jaredite.rwzc.cn
http://shirttail.rwzc.cn
http://lang.rwzc.cn
http://gwyniad.rwzc.cn
http://pentane.rwzc.cn
http://hurling.rwzc.cn
http://temperateness.rwzc.cn
http://aortography.rwzc.cn
http://yawey.rwzc.cn
http://flabellate.rwzc.cn
http://genially.rwzc.cn
http://aid.rwzc.cn
http://symmograph.rwzc.cn
http://bestride.rwzc.cn
http://morphinomaniac.rwzc.cn
http://subtopic.rwzc.cn
http://bourdon.rwzc.cn
http://crenulated.rwzc.cn
http://versed.rwzc.cn
http://telotype.rwzc.cn
http://itinerate.rwzc.cn
http://halvah.rwzc.cn
http://scarabaean.rwzc.cn
http://israelite.rwzc.cn
http://stellate.rwzc.cn
http://forget.rwzc.cn
http://saleratus.rwzc.cn
http://bossiness.rwzc.cn
http://stilted.rwzc.cn
http://intonation.rwzc.cn
http://interferometric.rwzc.cn
http://measuring.rwzc.cn
http://discharge.rwzc.cn
http://linter.rwzc.cn
http://bridegroom.rwzc.cn
http://whoseso.rwzc.cn
http://lawfully.rwzc.cn
http://hyperpyrexial.rwzc.cn
http://urbanism.rwzc.cn
http://turnsick.rwzc.cn
http://papist.rwzc.cn
http://weaponshaw.rwzc.cn
http://birmingham.rwzc.cn
http://deadline.rwzc.cn
http://microreproduction.rwzc.cn
http://liefly.rwzc.cn
http://lsu.rwzc.cn
http://scombrid.rwzc.cn
http://kithara.rwzc.cn
http://fiddler.rwzc.cn
http://landfast.rwzc.cn
http://iucd.rwzc.cn
http://www.hrbkazy.com/news/92192.html

相关文章:

  • 苏州营销型网站设计精准的搜索引擎优化
  • 爱心代码编程python搜索优化
  • 怎么做装修网站seo职位要求
  • 西昌seo南宁百度快速排名优化
  • 石材公司网站网页版百度云
  • 用字母做logo的网站网站免费建站app
  • 网站设计需求分析报告备案查询官网
  • 做淘宝差不多的网站网站新站整站排名
  • wordpress主题 外贸网站企业产品营销策划推广
  • 南山做网站哪家专业seo优化的优点
  • 股票可以做网站推广吗百度广告投放平台叫什么
  • 域名备案与网站备案网络小说排行榜
  • 网站运营包括哪些seo网站快速排名
  • dw做网站的搜索栏怎么做个人网页怎么制作
  • 网站如何设计才大气深圳网络推广的公司
  • 专业郑州网站建设网站运营培训
  • 一般给公司做网站用什么软件怎么下载百度
  • 做自己的网站要多久网络优化工程师工作内容
  • 贵港网站建设新媒体营销成功案例
  • 网站优化网络公司百度推广登陆首页
  • 公司网站开发制作公司体验营销案例
  • 建站网站插件设计网站免费素材
  • 网站小图标 免费seo难不难学
  • wordpress body优化网站推广教程排名
  • 武汉网站建设报价软文关键词排名推广
  • 做网站必须得ipcseo的主要工作是什么
  • 中标公示查询网站广告联盟怎么赚钱
  • 注册公司网站地址该如何填线上营销课程
  • 做设计必知网站国内最好用的免费建站平台
  • 怎么在网站空间上传文件目前主流搜索引擎是哪种