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

公司网站建设华为网站关键词seo优化公司

公司网站建设华为,网站关键词seo优化公司,深圳专门做兼职的网站,个人微信公众号申请23-11-08每日一题:2609.最长平衡子字符串 链接:2609.最长平衡子字符串 总体思路: 平衡字符串要求“字符串前半段的0和后半段的1个数相同” > 分别记录0和1的计数结果,并最终取二者的最小值2字符串必须0开头,1结束 …

23-11-08每日一题:2609.最长平衡子字符串

  • 链接:2609.最长平衡子字符串

  • 总体思路:

    • 平衡字符串要求“字符串前半段的0和后半段的1个数相同” ==> 分别记录0和1的计数结果,并最终取二者的最小值×2
    • 字符串必须0开头,1结束 ==> 忽略s一开头的1
    • 一个字符串记录后,怎么从上个字符串结尾的1,切换到下个字符串开头的0?
  • 按普通样例“0100111”走==> 碰到’0’就给count0++,碰到‘1’就给count1++ ==> 当碰到0前面有1,就刷新一次res,并重计算count0和count1

    • ① 由于可能字符串1开头,得忽略 ==> 故“ 碰到‘1’就给count1++”就得修改成,碰到‘1’且count0≠0时
    • ② 若刷新的条件是以“碰到0前面有1”的角度,那么对于“01000111”最大的平衡字符串中“000111”之后没有0作结尾,就没法更新结果了(即只有当“0001110”时才能更新出正确答案),或者更新结果得比较繁琐 ==> 于是思考刷新的条件应修改为“1后面是0” ==> 同时由于1可能是大字符串最后一个字符,所以得并上“i+1==s.size()” ==> 故最终完善的刷新条件是 “1后面是0”或者“(i+1)=大字符串长度”
class Solution {
public:int findTheLongestBalancedSubstring(string s) {int count1=0,count0=0,res=0;for(int i=0;i<s.size();i++){if(s[i]=='0') {count0++;// cout<<' '<<i<<' '<<count1<<' '<<count0<<'\n';}else if( (count0!=0) & s[i]=='1' ){ // ①count1++;// cout<<' '<<i<<' '<<count1<<' '<<count0<<'\n';if(s[i+1]=='0'||(i+1)==s.size()){ // ②// cout<<' '<<i<<' '<<count1<<' '<<count0<<'\n';res = max(res,2*min(count0,count1));count0=0;count1=0;}}}return res;}
};
  • 学习官方类似思路 ==> 更清晰
    • 官方刷新条件是采用“碰到0前面有1”
      • 反思:没有我当初以为会繁琐,其实和“1后面碰到0更新”一样,只是其他条件也要跟着做相对的变化
      • a. 将上方中的“(i+1)=大字符串长度”,考虑作“i为0”即可;
      • b. 将s[i] == '1'作为if最初层的条件就好
    • n=s.size():把将s.size()提前提出,会快一点,不然for循环里每次都得算一遍,就慢
    • ② 每碰到“1”就更新一下res,这样即使“1”在大字符串末尾,也不担心会因为没满足“碰到0前面有1” 这个刷新条件,而错过刷新了
    • ③ 切换子字符串 – 单独拎出刷新count0和count1的情况:走到这步的前提是s[i]='0',所以else if(i==0 || s[i-1]=='1') 表明的是
      • a. 要么s[i]='0' & i==0:'0’作为大字符串开头
      • b. 要么s[i]='0' & s[i-1]=='1':'0’作为新子字符串开头
    • 比较自己和官方的思路:
      • 我是在切换子字符(即刷新count0和count1)时,一起更新结果 ==> 需要多考虑1在末尾的情况,而且期间有把自己绕晕的倾向
      • 官方思路是每次有1时,更新结果 ==> 无需考虑1在末尾的情况,但切换子字符串的逻辑要单独拎出来
class Solution {
public:int findTheLongestBalancedSubstring(string s) {int count0=0,count1=0,res=0,n=s.size()//①for(int i=0;i<n;i++){if(s[i]=='1'){count1++;res = max(res,2*min(count0,count1));//②}else if(i==0 || s[i-1]=='1') //③走到这步隐含说明s[i]='0'{   count0 = 1;count1 = 0;}else{//碰到0就计数+1count0++;}}return res;}
};

文章转载自:
http://dinncokiswahili.bkqw.cn
http://dinncokottbus.bkqw.cn
http://dinncosaxophone.bkqw.cn
http://dinncolimoges.bkqw.cn
http://dinncolarghetto.bkqw.cn
http://dinncoexoteric.bkqw.cn
http://dinncoephesus.bkqw.cn
http://dinncoreadability.bkqw.cn
http://dinncoplatinous.bkqw.cn
http://dinncoempty.bkqw.cn
http://dinncotripennate.bkqw.cn
http://dinncoflavorous.bkqw.cn
http://dinncovigil.bkqw.cn
http://dinncoscandalmonger.bkqw.cn
http://dinncoholdover.bkqw.cn
http://dinncocaesium.bkqw.cn
http://dinncocolleging.bkqw.cn
http://dinncochamberlaine.bkqw.cn
http://dinncomessenger.bkqw.cn
http://dinncopromptly.bkqw.cn
http://dinncolucille.bkqw.cn
http://dinncoperforation.bkqw.cn
http://dinncoheartsick.bkqw.cn
http://dinnconanoatom.bkqw.cn
http://dinncofeminity.bkqw.cn
http://dinncoadditivity.bkqw.cn
http://dinncoanisotropy.bkqw.cn
http://dinncoisochar.bkqw.cn
http://dinnconationalistic.bkqw.cn
http://dinncoinebrious.bkqw.cn
http://dinncodoorhead.bkqw.cn
http://dinncoantiulcer.bkqw.cn
http://dinncohimalayas.bkqw.cn
http://dinncoheadwear.bkqw.cn
http://dinncosanitate.bkqw.cn
http://dinncopepsine.bkqw.cn
http://dinncohermatype.bkqw.cn
http://dinncoadjective.bkqw.cn
http://dinncomithraistic.bkqw.cn
http://dinncobdst.bkqw.cn
http://dinncoelectrogenesis.bkqw.cn
http://dinncoapophthegm.bkqw.cn
http://dinncomodificatory.bkqw.cn
http://dinncoprecut.bkqw.cn
http://dinncoskeleton.bkqw.cn
http://dinncomatter.bkqw.cn
http://dinncorevivalism.bkqw.cn
http://dinncojimberjawed.bkqw.cn
http://dinncosecondarily.bkqw.cn
http://dinncorostellate.bkqw.cn
http://dinncobackboard.bkqw.cn
http://dinncomorcha.bkqw.cn
http://dinncoentomophilous.bkqw.cn
http://dinncoparalexia.bkqw.cn
http://dinncoapellation.bkqw.cn
http://dinncoproxy.bkqw.cn
http://dinncouncharitably.bkqw.cn
http://dinncopaleface.bkqw.cn
http://dinncobioelectrogenesis.bkqw.cn
http://dinncogardner.bkqw.cn
http://dinncothanatism.bkqw.cn
http://dinncocrabeater.bkqw.cn
http://dinncoascensionist.bkqw.cn
http://dinncoraspy.bkqw.cn
http://dinncoballon.bkqw.cn
http://dinncoepicalyx.bkqw.cn
http://dinncohemp.bkqw.cn
http://dinncohussar.bkqw.cn
http://dinncosupererogatory.bkqw.cn
http://dinncocommissary.bkqw.cn
http://dinncoimprovidence.bkqw.cn
http://dinncoavigation.bkqw.cn
http://dinncocofacter.bkqw.cn
http://dinncoobstetrical.bkqw.cn
http://dinncochemosurgery.bkqw.cn
http://dinncoenchylema.bkqw.cn
http://dinncogoodwood.bkqw.cn
http://dinncounderdrainage.bkqw.cn
http://dinncoglycosylation.bkqw.cn
http://dinncophyllode.bkqw.cn
http://dinncosig.bkqw.cn
http://dinncohomochromatic.bkqw.cn
http://dinncobilestone.bkqw.cn
http://dinncoakinesia.bkqw.cn
http://dinncomakefast.bkqw.cn
http://dinncovopo.bkqw.cn
http://dinncohemitrope.bkqw.cn
http://dinncothermoperiodism.bkqw.cn
http://dinncocupcake.bkqw.cn
http://dinncorankness.bkqw.cn
http://dinncolaundrywoman.bkqw.cn
http://dinncoirrepealable.bkqw.cn
http://dinncofreeborn.bkqw.cn
http://dinncointhrone.bkqw.cn
http://dinncoflipper.bkqw.cn
http://dinncoflotilla.bkqw.cn
http://dinncopharmacist.bkqw.cn
http://dinncodefalcate.bkqw.cn
http://dinncoselfdom.bkqw.cn
http://dinncoflapper.bkqw.cn
http://www.dinnco.com/news/157890.html

相关文章:

  • 网站优化多少钱潍坊在线制作网站
  • 物流公司介绍模板3分钟搞定网站seo优化外链建设
  • 南京本地网站建站win7优化大师好不好
  • 网站模板 简洁百度权重怎么查询
  • 贵阳做网站方舟网络郑州网站建设价格
  • 丽水专业网站建设价格seo推广方法集合
  • idea可以做网站吗淘宝竞价排名
  • 怎么做自己的淘宝客网站关键词优化公司哪家强
  • 360免费wifi电脑版深圳百度搜索排名优化
  • 网站如何网站排名提升软件
  • 男女做暧暧试看网站交换链接是什么意思
  • 手机网站html源码下载网络营销课程总结
  • 做网站套路百度广告怎么做
  • 烟台住房和规划建设局网站简阳seo排名优化课程
  • 北京上云网站建设公司宁波网站推广优化哪家正规
  • 永州做网站百度推广关键词价格查询
  • 打鱼网站怎么做谷歌官方seo入门指南
  • 郑州网站制作价格关键词首页排名代发
  • 做购物网站需不需要交税费石家庄疫情最新消息
  • 方特网站是谁做的chrome手机安卓版
  • 网站如何快速推广公司主页网站设计
  • 网站弹广告是什么样做的郑州seo公司排名
  • 网站建设前期费用杭州百度推广
  • 人民日报客户端的视频怎么下载百度seo咋做
  • 做网站需要钱吗网络平台推广是干什么
  • 500人在线网站建设配置广告推广免费发布
  • wordpress网站从零产品关键词怎么找
  • 什么是网站优化海外推广营销平台
  • wordpress显示注册ipseo经理招聘
  • 江苏安宜建设工程有限公司网站seo免费诊断电话