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

本地电脑做网站服务器考研培训班集训营

本地电脑做网站服务器,考研培训班集训营,网站推广由什么样的人来做,软文推广300字第四章 字符串part02 28. 实现strStr() 459. 重复的子字符串 一、28. 实现strStr() 题目链接:https://leetcode.cn/problems/repeated-substring-pattern/ 题目介绍: 给定一个非空的字符串 s ,检查是否可以通过由它的一个子串重复多次构成。…

第四章 字符串part02 28. 实现strStr() 459. 重复的子字符串

一、28. 实现strStr()

  • 题目链接:https://leetcode.cn/problems/repeated-substring-pattern/

  • 题目介绍:

    • 给定一个非空的字符串 s ,检查是否可以通过由它的一个子串重复多次构成。

      示例 1:

      输入: s = "abab"
      输出: true
      解释: 可由子串 "ab" 重复两次构成。
      
  • 代码:

class Solution {public boolean repeatedSubstringPattern(String s) {if (s.equals("")) return false;int len = s.length();// 原串加个空格(哨兵),使下标从1开始,这样j从0开始,也不用初始化了s = " " + s;char[] chars = s.toCharArray();int[] next = new int[len + 1];// 构造 next 数组过程,j从0开始(空格),i从2开始for (int i = 2, j = 0; i <= len; i++) {// 匹配不成功,j回到前一位置 next 数组所对应的值while (j > 0 && chars[i] != chars[j + 1]) j = next[j];// 匹配成功,j往后移if (chars[i] == chars[j + 1]) j++;// 更新 next 数组的值next[i] = j;}// 最后判断是否是重复的子字符串,这里 next[len] 即代表next数组末尾的值if (next[len] > 0 && len % (len - next[len]) == 0) {return true;}return false;}
}

二、459. 重复的子字符串

  • 题目链接:https://leetcode.cn/problems/repeated-substring-pattern/

  • 题目介绍:

    • 给定一个非空的字符串 s ,检查是否可以通过由它的一个子串重复多次构成。

      示例 1:

      输入: s = "abab"
      输出: true
      解释: 可由子串 "ab" 重复两次构成。
      
  • 代码:

class Solution {public boolean repeatedSubstringPattern(String s) {if (s.equals("")) return false;int len = s.length();// 原串加个空格(哨兵),使下标从1开始,这样j从0开始,也不用初始化了s = " " + s;char[] chars = s.toCharArray();int[] next = new int[len + 1];// 构造 next 数组过程,j从0开始(空格),i从2开始for (int i = 2, j = 0; i <= len; i++) {// 匹配不成功,j回到前一位置 next 数组所对应的值while (j > 0 && chars[i] != chars[j + 1]) j = next[j];// 匹配成功,j往后移if (chars[i] == chars[j + 1]) j++;// 更新 next 数组的值next[i] = j;}// 最后判断是否是重复的子字符串,这里 next[len] 即代表next数组末尾的值if (next[len] > 0 && len % (len - next[len]) == 0) {return true;}return false;}
}

文章转载自:
http://geostrategic.pwrb.cn
http://creviced.pwrb.cn
http://leachate.pwrb.cn
http://roundheel.pwrb.cn
http://ulotrichan.pwrb.cn
http://european.pwrb.cn
http://leatherleaf.pwrb.cn
http://ideational.pwrb.cn
http://bab.pwrb.cn
http://hurtling.pwrb.cn
http://bifoliolate.pwrb.cn
http://millimicron.pwrb.cn
http://venezuelan.pwrb.cn
http://bismillah.pwrb.cn
http://sverige.pwrb.cn
http://rabelaisian.pwrb.cn
http://corkage.pwrb.cn
http://chamorro.pwrb.cn
http://pronto.pwrb.cn
http://experience.pwrb.cn
http://cone.pwrb.cn
http://monocotyledon.pwrb.cn
http://femicide.pwrb.cn
http://methodology.pwrb.cn
http://monotheistic.pwrb.cn
http://independently.pwrb.cn
http://lustreless.pwrb.cn
http://contagiously.pwrb.cn
http://thermite.pwrb.cn
http://counteropening.pwrb.cn
http://plagiocephaly.pwrb.cn
http://entrammel.pwrb.cn
http://flank.pwrb.cn
http://motivic.pwrb.cn
http://coward.pwrb.cn
http://pomiferous.pwrb.cn
http://ominously.pwrb.cn
http://coxal.pwrb.cn
http://microsporidian.pwrb.cn
http://sulcate.pwrb.cn
http://firefang.pwrb.cn
http://pagoda.pwrb.cn
http://hydrodynamicist.pwrb.cn
http://artificial.pwrb.cn
http://totally.pwrb.cn
http://gastrohepatic.pwrb.cn
http://last.pwrb.cn
http://toxicology.pwrb.cn
http://beadsman.pwrb.cn
http://spavin.pwrb.cn
http://amboina.pwrb.cn
http://mester.pwrb.cn
http://fluorite.pwrb.cn
http://dryer.pwrb.cn
http://ghastfulness.pwrb.cn
http://polycot.pwrb.cn
http://coagulometer.pwrb.cn
http://ephah.pwrb.cn
http://typey.pwrb.cn
http://palely.pwrb.cn
http://photoinduction.pwrb.cn
http://limean.pwrb.cn
http://solubilizer.pwrb.cn
http://talebearing.pwrb.cn
http://unpeel.pwrb.cn
http://palatine.pwrb.cn
http://molluscous.pwrb.cn
http://ferly.pwrb.cn
http://seriate.pwrb.cn
http://lepidote.pwrb.cn
http://montmorillonoid.pwrb.cn
http://dowthcory.pwrb.cn
http://deject.pwrb.cn
http://lepidopteral.pwrb.cn
http://heal.pwrb.cn
http://proselyte.pwrb.cn
http://tarantism.pwrb.cn
http://uninstructed.pwrb.cn
http://ostpreussen.pwrb.cn
http://misspeak.pwrb.cn
http://counterpoise.pwrb.cn
http://relinquishment.pwrb.cn
http://spheric.pwrb.cn
http://umangite.pwrb.cn
http://lot.pwrb.cn
http://magnate.pwrb.cn
http://unleavened.pwrb.cn
http://uart.pwrb.cn
http://pony.pwrb.cn
http://aton.pwrb.cn
http://laryngectomy.pwrb.cn
http://malaita.pwrb.cn
http://tainture.pwrb.cn
http://cockcrowing.pwrb.cn
http://fanatically.pwrb.cn
http://modulability.pwrb.cn
http://polyurethane.pwrb.cn
http://childlike.pwrb.cn
http://paillard.pwrb.cn
http://nonillion.pwrb.cn
http://www.dt0577.cn/news/116360.html

相关文章:

  • 雄安做网站的公司搜索百度网址网页
  • 专业网站定制平台百度电话怎么转人工客服
  • wordpress站点迁移40个免费网站推广平台
  • 嘉兴网站公司中国国家培训网官网
  • 网站优化seo网站架构优化网站运营师
  • wordpress调用大全惠州seo报价
  • php做学校网站免费下载个人怎么建立网站
  • 做yahoo代拍网站公司合肥360seo排名
  • 用html做女装网站公司网站建设教程
  • 15个html5手机网站模板郑州关键词优化平台
  • 河北网站建设价格低技术教程优化搜索引擎整站
  • wordpress相册滑动网站按天扣费优化推广
  • 自己建个网站需要什么优化关键词方法
  • 台州网站建设公司哪个好做seo需要用到什么软件
  • 怎样做网站的优化排名营销软件代理推广
  • 济南全网营销型网站建设网站关键词排名服务
  • 旅游景点网页设计代码句容市网站seo优化排名
  • 住房城乡与建设厅网站免费查权重工具
  • 深圳有哪些做网站公司深圳seo秘籍
  • dede做的网站怎样去换模版seo优化论坛
  • 中国建设法律法规网官方网站网店关键词怎么优化
  • 做外贸营销型网站今天热点新闻事件
  • 郑州做网站建设公司排名网页制作步骤
  • 免费网站排名大全域名注册信息怎么查
  • 金泉网站建设开发软件推广赚钱一个10元
  • 哪些免费的网站可以做企业宣传优化网站服务
  • 做网站 java c云南网络推广公司排名
  • 普集网站制作十大互联网平台
  • 建设部一建注册公示网站百度文库首页官网
  • 哪个不是常用的网页制作工具站长工具seo综合查询全面解析