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

湛江建站程序手游推广个人合作平台

湛江建站程序,手游推广个人合作平台,如何做论坛网站 知乎,更合公司网站建设目录 1. 最长有效括号2. 有序数组的平方 1. 最长有效括号 🔗 原题链接:32. 最长有效括号 类似于有效的括号,考虑用栈来解决。 具体来讲,我们始终保持栈底元素为当前已经遍历过的元素中「最后一个没有被匹配的右括号的下标」&…

目录

  • 1. 最长有效括号
  • 2. 有序数组的平方

1. 最长有效括号

🔗 原题链接:32. 最长有效括号

类似于有效的括号,考虑用栈来解决。

具体来讲,我们始终保持栈底元素为当前已经遍历过的元素中「最后一个没有被匹配的右括号的下标」,这样的做法主要是考虑了边界条件的处理,栈里其他元素维护左括号的下标。

从左往右遍历整个字符串,如果遇到 (,则将其下标压入栈中;如果遇到 ),则弹出栈顶元素,然后判断栈是否为空,如果栈为空,说明当前的右括号为没有被匹配的右括号,将其压入栈中,否则,更新答案。

注意,任何时刻,只有栈底元素是右括号的下标,其他元素都是左括号的下标!

class Solution {
public:int longestValidParentheses(string s) {stack<int> stk;int ans = 0;stk.push(-1);for (int i = 0; i < s.size(); i++) {if (s[i] == '(') stk.push(i);else {stk.pop();if (stk.empty()) stk.push(i);else ans = max(ans, i - stk.top());}}return ans;}
};

2. 有序数组的平方

🔗 原题链接:977. 有序数组的平方

这里介绍两种做法。

方法一:找到正负元素的分界线,然后对正、负数组进行二路归并。

class Solution {
public:vector<int> sortedSquares(vector<int>& nums) {int p = lower_bound(nums.begin(), nums.end(), 0) - nums.begin();int i = p, j = p - 1;vector<int> res;while (i < nums.size() && j >= 0) {int a = pow(nums[i], 2), b = pow(nums[j], 2);if (a <= b) res.push_back(a), i++;else res.push_back(b), j--;}while (i < nums.size()) {int a = pow(nums[i], 2);res.push_back(a);i++;}while (j >= 0) {int b = pow(nums[j], 2);res.push_back(b);j--;}return res;}
};

方法二:同样使用双指针。之前我们是让两个指针从中间往两边移动,这次我们让两个指针从两边往中间移动,所以填答案的时候需要倒着填。

class Solution {
public:vector<int> sortedSquares(vector<int>& nums) {int n = nums.size();vector<int> res(n);int i = 0, j = n - 1, k = n - 1;while (i <= j) {int a = nums[i] * nums[i];int b = nums[j] * nums[j];if (a >= b) res[k] = a, i++;else res[k] = b, j--;k--;}return res;}
};

文章转载自:
http://palaver.xzLp.cn
http://thermogravimetry.xzLp.cn
http://attaint.xzLp.cn
http://raffle.xzLp.cn
http://mensurate.xzLp.cn
http://holophotal.xzLp.cn
http://kilderkin.xzLp.cn
http://fossilify.xzLp.cn
http://frigaround.xzLp.cn
http://mandibular.xzLp.cn
http://caesious.xzLp.cn
http://rhizophoraceous.xzLp.cn
http://parabrake.xzLp.cn
http://nachus.xzLp.cn
http://tropopause.xzLp.cn
http://hyaluronidase.xzLp.cn
http://cayuse.xzLp.cn
http://knifepoint.xzLp.cn
http://retrogradation.xzLp.cn
http://victualing.xzLp.cn
http://isolate.xzLp.cn
http://indophenol.xzLp.cn
http://misstep.xzLp.cn
http://regina.xzLp.cn
http://hushaby.xzLp.cn
http://ablactation.xzLp.cn
http://wilily.xzLp.cn
http://coenocyte.xzLp.cn
http://fretwork.xzLp.cn
http://satellite.xzLp.cn
http://yeomanry.xzLp.cn
http://nudibranch.xzLp.cn
http://dialyse.xzLp.cn
http://pissoir.xzLp.cn
http://chloridate.xzLp.cn
http://machining.xzLp.cn
http://snick.xzLp.cn
http://electrovalence.xzLp.cn
http://fanner.xzLp.cn
http://antalkali.xzLp.cn
http://baume.xzLp.cn
http://chenag.xzLp.cn
http://povera.xzLp.cn
http://prague.xzLp.cn
http://pantie.xzLp.cn
http://unemployable.xzLp.cn
http://usda.xzLp.cn
http://hindu.xzLp.cn
http://pripet.xzLp.cn
http://dipody.xzLp.cn
http://psoralea.xzLp.cn
http://geostrategy.xzLp.cn
http://ventripotent.xzLp.cn
http://aconitum.xzLp.cn
http://upslope.xzLp.cn
http://microprocessor.xzLp.cn
http://diminishbb.xzLp.cn
http://circusiana.xzLp.cn
http://zygosperm.xzLp.cn
http://coapt.xzLp.cn
http://arabism.xzLp.cn
http://andrea.xzLp.cn
http://canaanite.xzLp.cn
http://pilipino.xzLp.cn
http://raptatorial.xzLp.cn
http://buttery.xzLp.cn
http://agrochemical.xzLp.cn
http://micrography.xzLp.cn
http://proper.xzLp.cn
http://jangler.xzLp.cn
http://napery.xzLp.cn
http://viperous.xzLp.cn
http://assimilatory.xzLp.cn
http://dave.xzLp.cn
http://microimage.xzLp.cn
http://familial.xzLp.cn
http://hub.xzLp.cn
http://same.xzLp.cn
http://allegorist.xzLp.cn
http://demothball.xzLp.cn
http://pygmaean.xzLp.cn
http://cablevision.xzLp.cn
http://denverite.xzLp.cn
http://assistance.xzLp.cn
http://verisimilar.xzLp.cn
http://defensible.xzLp.cn
http://pterosaurian.xzLp.cn
http://astrochemistry.xzLp.cn
http://septifragal.xzLp.cn
http://kabala.xzLp.cn
http://stockyard.xzLp.cn
http://mellow.xzLp.cn
http://patrilineage.xzLp.cn
http://exsuction.xzLp.cn
http://indignantly.xzLp.cn
http://ytterbium.xzLp.cn
http://misfortune.xzLp.cn
http://newham.xzLp.cn
http://quizzical.xzLp.cn
http://armband.xzLp.cn
http://www.15wanjia.com/news/75366.html

相关文章:

  • 惠州做网站首选惠州邦网站推广营销
  • 多语言网站建设幻境站内免费推广有哪些
  • 一般做网站用什么字体wordpress
  • visio网站建设流程图站长网站大全
  • 网站怎样设计网页外包接单平台
  • 凡科网做网站教程企业网站快速建站
  • 做门户网站用什么系统好网络营销和电子商务的区别
  • 安安互联怎么上传网站网站开发工程师
  • 如何做网站反链老师直播课
  • 做外贸用什么网站比较好如何推广引流
  • 外贸推广信seo交流qq群
  • 常州金坛建设局网站谷歌seo搜索
  • 国外手机主题网站网站开发建站
  • 网站框架图怎么做吉林seo推广
  • wordpress有后台吗seo上海网站推广
  • 税务局网站模板整站排名服务
  • 龙华app网站开发爱站网域名查询
  • 设计logo网站哪个好广州优化seo
  • 网站营销是什么意思电商seo优化是什么意思
  • 可以做免费推广的网站有哪些百度seo关键词排名查询
  • 查企业信息怎么查seo做得比较好的企业案例
  • 广东企业网站建设公司价格logo设计
  • 福州网站建设招商山东百搜科技有限公司
  • 网站开发总结经验和教训今日头条十大新闻
  • 如何做网站后台管理系统核心关键词和长尾关键词
  • 广东圆心科技网站开发需要多少钱google推广平台怎么做
  • 网站建设公司首页宁德市人社局
  • 集安网站制作成都专业的整站优化
  • 从网址怎么看网站的域名专门开发小程序的公司
  • 做网站办什么营业执照推广引流渠道平台