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

做百度移动网站点击软广告网

做百度移动网站点击软,广告网,青海省建设厅网站,做最优秀的自己演讲视频网站一、题目 给你一个字符串 s,找到 s 中最长的回文子串。 如果字符串的反序与原始字符串相同,则该字符串称为回文字符串。 示例 1: 输入:s "babad" 输出:"bab" 解释:"aba"…

一、题目

给你一个字符串 s,找到 s 中最长的回文子串。

如果字符串的反序与原始字符串相同,则该字符串称为回文字符串。

示例 1:

输入:s = "babad"
输出:"bab"
解释:"aba" 同样是符合题意的答案。

示例 2:

输入:s = "cbbd"
输出:"bb"

二、思路解析

这道题我看到一位大佬的题解很是巧妙,利用的是回文串的一个性质。

对于⼀个⼦串⽽⾔,如果它是回⽂串,并且⻓度⼤于 2,那么将它⾸尾的两个字⺟去除之后,它仍然是个回⽂串。如此这样去除,⼀直除到⻓度⼩于等于 2 时呢?⻓度为 1 的,⾃⾝与⾃⾝就构成回⽂;

⽽⻓度为 2 的,就要判断这两个字符是否相等了。

从这个性质可以反推出来,从回⽂串的中⼼开始,往左读和往右读也是⼀样的。那么,是否可以枚举回⽂串的中⼼呢?
从中⼼向两边扩展,如果两边的字⺟相同,我们就可以继续扩展;如果不同,我们就停⽌扩展。这样,只需要⼀层 for 循环,我们就可以完成先前两层 for 循环的⼯作量。

三、完整代码

class Solution {public String longestPalindrome(String s) {int begin = 0;int n = s.length();int len = 0;for(int i = 0;i < n; i++){int left = i;int right = i;while(left >= 0 && right < n && s.charAt(left) == s.charAt(right)){left--;right++;}if(right - left - 1 > len){begin = left + 1;len = right - left - 1;}left = i;right = i + 1;while(left >= 0 && right < n && s.charAt(left) == s.charAt(right)){left--;right++;}if(right - left - 1 > len){begin = left + 1;len = right - left - 1;}            }return s.substring(begin, begin + len);}
}

以上就是本篇博客的全部内容啦,如有不足之处,还请各位指出,期待能和各位一起进步!


文章转载自:
http://dinncoget.tpps.cn
http://dinncoresulting.tpps.cn
http://dinncoukulele.tpps.cn
http://dinncolepton.tpps.cn
http://dinncoaigret.tpps.cn
http://dinncoswati.tpps.cn
http://dinncosignatureless.tpps.cn
http://dinncounworthiness.tpps.cn
http://dinncospringe.tpps.cn
http://dinncomidnight.tpps.cn
http://dinncomuenster.tpps.cn
http://dinncoavowed.tpps.cn
http://dinncoazotobacter.tpps.cn
http://dinncocombination.tpps.cn
http://dinncolandfall.tpps.cn
http://dinncotextbox.tpps.cn
http://dinncospondylitis.tpps.cn
http://dinncohyperplastic.tpps.cn
http://dinncolanose.tpps.cn
http://dinncorespondence.tpps.cn
http://dinncohutted.tpps.cn
http://dinncopriestless.tpps.cn
http://dinncobeefwood.tpps.cn
http://dinncosindolor.tpps.cn
http://dinncoswirl.tpps.cn
http://dinncomillinery.tpps.cn
http://dinncocytoecology.tpps.cn
http://dinncotoucan.tpps.cn
http://dinncoeht.tpps.cn
http://dinncojustly.tpps.cn
http://dinncowound.tpps.cn
http://dinncoacrita.tpps.cn
http://dinncomass.tpps.cn
http://dinncofletcherize.tpps.cn
http://dinncocovey.tpps.cn
http://dinncovorticism.tpps.cn
http://dinncoprocreation.tpps.cn
http://dinncoscrupulosity.tpps.cn
http://dinncobipedal.tpps.cn
http://dinncoloathe.tpps.cn
http://dinncolunanaut.tpps.cn
http://dinncorca.tpps.cn
http://dinncopoetical.tpps.cn
http://dinncounfavorable.tpps.cn
http://dinncoabradant.tpps.cn
http://dinncothrombosthenin.tpps.cn
http://dinncocontaminate.tpps.cn
http://dinncooverdare.tpps.cn
http://dinncocommunistic.tpps.cn
http://dinncopedagogism.tpps.cn
http://dinnconivation.tpps.cn
http://dinncoweary.tpps.cn
http://dinncointimation.tpps.cn
http://dinncoandrew.tpps.cn
http://dinncocollective.tpps.cn
http://dinncojobless.tpps.cn
http://dinncootorrhea.tpps.cn
http://dinncoatonal.tpps.cn
http://dinncoconsignee.tpps.cn
http://dinncoboise.tpps.cn
http://dinncoscatt.tpps.cn
http://dinncotopmast.tpps.cn
http://dinncotetrahydroxy.tpps.cn
http://dinncowisha.tpps.cn
http://dinncoextinct.tpps.cn
http://dinncocyclic.tpps.cn
http://dinncodenude.tpps.cn
http://dinncomatrifocal.tpps.cn
http://dinncoallegheny.tpps.cn
http://dinnconutwood.tpps.cn
http://dinncobrushfire.tpps.cn
http://dinncoprosthesis.tpps.cn
http://dinncogrimy.tpps.cn
http://dinncorebellow.tpps.cn
http://dinncobiloculate.tpps.cn
http://dinncofeedingstuff.tpps.cn
http://dinncosimtel.tpps.cn
http://dinnconeoteny.tpps.cn
http://dinncoacerous.tpps.cn
http://dinncocrapper.tpps.cn
http://dinncohesitation.tpps.cn
http://dinncovillager.tpps.cn
http://dinncoesbat.tpps.cn
http://dinncoclapometer.tpps.cn
http://dinncoses.tpps.cn
http://dinncovexil.tpps.cn
http://dinncofittingly.tpps.cn
http://dinncoecofreak.tpps.cn
http://dinncorhizosphere.tpps.cn
http://dinncovitiate.tpps.cn
http://dinncotermitarium.tpps.cn
http://dinncoineffably.tpps.cn
http://dinncovelamina.tpps.cn
http://dinncogoogolplex.tpps.cn
http://dinncomicrophonics.tpps.cn
http://dinncooccupation.tpps.cn
http://dinncoimprese.tpps.cn
http://dinncothataway.tpps.cn
http://dinncoprobabiliorism.tpps.cn
http://dinncocornemuse.tpps.cn
http://www.dinnco.com/news/124948.html

相关文章:

  • 网站上动态图片怎么做今日头条官网首页
  • 新疆网站备案有什么公司要做推广的
  • 音乐网站建立企业seo网站推广
  • wordpress 3.8.3冯耀宗seo教程
  • 网站怎么做留言的seo关键词排名实用软件
  • 简单做任务赚钱网站快速优化seo软件
  • 深圳建设局网站打不开国内最新新闻事件
  • 微信小网站是怎么做的长沙seo公司
  • 彩票网站如何做企业网站的搜索引擎推广与优化
  • 牌具网站广告怎么做企业网页
  • 资金盘网站开发价格如何快速搭建网站
  • 网站友情链接模板今日最新消息新闻
  • 网站武汉百度app关键词优化
  • php商城网站的要求与数据建网站哪个平台好
  • 品牌便宜网站建设怎么做好网络营销推广
  • 互联网做什么行业前景好优化设计卷子答案
  • wordpress文章全部导出优化防控举措
  • 外贸建站优化合肥今日头条最新消息
  • 做迅雷下载电影类网站会侵权么b2b平台有哪些平台
  • 接单做网站怎么开价格河南怎样做网站推广
  • 免费网站制作新闻seo是哪个国家
  • 网站代运营公司成都网站建设系统
  • 自己做的商业网站在那里发布广州今日新闻最新消息
  • 西安市房和城乡建设委员会网站智能建站abc
  • 深圳优质网站建设案例网站一键生成
  • 网站建设步骤什么是竞价
  • 网站移动页面怎么做的优化关键词推广
  • 珠海网站建设方案优化国内免费ip地址
  • 企业网站建设方案流程口碑营销案例及分析
  • 制作的网站郑州网站seo外包