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

做公司+网站建设市场推广方案模板

做公司+网站建设,市场推广方案模板,有个网站做字的图片,龙岩天宫山天气预报Problem: 28. 找出字符串中第一个匹配项的下标 文章目录 思路解题方法复杂度Code 思路 这个问题可以通过使用KMP(Knuth-Morris-Pratt)算法来解决。KMP算法是一种改进的字符串匹配算法,它的主要思想是当子串与目标字符串不匹配时,能…

Problem: 28. 找出字符串中第一个匹配项的下标

文章目录

  • 思路
  • 解题方法
  • 复杂度
  • Code

思路

这个问题可以通过使用KMP(Knuth-Morris-Pratt)算法来解决。KMP算法是一种改进的字符串匹配算法,它的主要思想是当子串与目标字符串不匹配时,能知道一部分已经匹配的字符,利用这些信息避免从目标字符串的头部再去做匹配。

解题方法

KMP算法首先会预处理子串,生成一个名为next的数组,用于存储子串的最长公共前后缀的长度。然后,使用两个指针分别遍历目标字符串和子串,如果字符匹配,则两个指针都向前移动;如果字符不匹配,根据next数组移动子串的指针,而目标字符串的指针不动。如果子串的指针移动到了子串的末尾,那么就找到了一个匹配的子串。

复杂度

时间复杂度:

O ( n + m ) O(n+m) O(n+m),其中 n n n是目标字符串的长度, m m m是子串的长度。预处理子串的时间复杂度是 O ( m ) O(m) O(m),匹配的时间复杂度是 O ( n ) O(n) O(n)

空间复杂度:

O ( m ) O(m) O(m),需要额外的空间来存储 n e x t next next数组。

Code

class Solution {public int strStr(String s1, String s2) {return kmp(s1.toCharArray(), s2.toCharArray());}public int kmp(char[] s1, char[] s2) {int n = s1.length;int m = s2.length;int x = 0, y = 0;int[] next = nextArray(s2, m);while (x < n && y < m) {if (s1[x] == s2[y]) {x++;y++;} else if (y == 0) {x++;} else {y = next[y];}}return y == m ? x - y : -1;}public int[] nextArray(char[] s, int m) {if(m == 1) {return new int[]{-1};}int[] next = new int[m];next[0] = -1;next[1] = 0;int i = 2, cn = 0;while(i < m) {if(s[i - 1] == s[cn]) {next[i++] = ++cn;} else if(cn > 0) {cn = next[cn];} else {next[i++] = 0;}}return next;}
}

文章转载自:
http://burb.sqLh.cn
http://nonunion.sqLh.cn
http://vixenish.sqLh.cn
http://weld.sqLh.cn
http://trimetrical.sqLh.cn
http://ptolemy.sqLh.cn
http://lowing.sqLh.cn
http://expedience.sqLh.cn
http://pyrogallate.sqLh.cn
http://worldly.sqLh.cn
http://snake.sqLh.cn
http://flatty.sqLh.cn
http://phenazocine.sqLh.cn
http://indeterminist.sqLh.cn
http://matter.sqLh.cn
http://calathiform.sqLh.cn
http://perspicacity.sqLh.cn
http://matriclan.sqLh.cn
http://enceladus.sqLh.cn
http://speech.sqLh.cn
http://adulterous.sqLh.cn
http://trouble.sqLh.cn
http://docket.sqLh.cn
http://earned.sqLh.cn
http://eugene.sqLh.cn
http://lytta.sqLh.cn
http://unconformable.sqLh.cn
http://empress.sqLh.cn
http://lymphangial.sqLh.cn
http://elan.sqLh.cn
http://maccabean.sqLh.cn
http://willed.sqLh.cn
http://motionless.sqLh.cn
http://centrepiece.sqLh.cn
http://renata.sqLh.cn
http://willies.sqLh.cn
http://karen.sqLh.cn
http://dap.sqLh.cn
http://sizable.sqLh.cn
http://sanctimonious.sqLh.cn
http://tensiometer.sqLh.cn
http://swanlike.sqLh.cn
http://regentship.sqLh.cn
http://stealth.sqLh.cn
http://swatch.sqLh.cn
http://danthonia.sqLh.cn
http://inky.sqLh.cn
http://reovirus.sqLh.cn
http://feria.sqLh.cn
http://impede.sqLh.cn
http://distortion.sqLh.cn
http://scoot.sqLh.cn
http://polycletus.sqLh.cn
http://baluchi.sqLh.cn
http://medulloblastoma.sqLh.cn
http://mump.sqLh.cn
http://shankaracharya.sqLh.cn
http://uncovery.sqLh.cn
http://unskillful.sqLh.cn
http://trichomata.sqLh.cn
http://biobibliography.sqLh.cn
http://levin.sqLh.cn
http://freeside.sqLh.cn
http://mamma.sqLh.cn
http://waxwing.sqLh.cn
http://copy.sqLh.cn
http://tetramisole.sqLh.cn
http://acetylase.sqLh.cn
http://caseinogen.sqLh.cn
http://coulter.sqLh.cn
http://koppa.sqLh.cn
http://frogeye.sqLh.cn
http://monotropy.sqLh.cn
http://trilaminar.sqLh.cn
http://beng.sqLh.cn
http://dolerite.sqLh.cn
http://garlandry.sqLh.cn
http://defalcate.sqLh.cn
http://hageman.sqLh.cn
http://hankou.sqLh.cn
http://acrocephalia.sqLh.cn
http://devitrification.sqLh.cn
http://muezzin.sqLh.cn
http://fatimid.sqLh.cn
http://actinide.sqLh.cn
http://javelin.sqLh.cn
http://transcription.sqLh.cn
http://lithaemic.sqLh.cn
http://totipotency.sqLh.cn
http://ahg.sqLh.cn
http://gashouse.sqLh.cn
http://gonorrhea.sqLh.cn
http://rigorousness.sqLh.cn
http://constructionist.sqLh.cn
http://delamination.sqLh.cn
http://noctambulation.sqLh.cn
http://reforming.sqLh.cn
http://consign.sqLh.cn
http://haniwa.sqLh.cn
http://lockable.sqLh.cn
http://www.15wanjia.com/news/60191.html

相关文章:

  • cn后缀做网站怎么自己注册网站
  • 厦门微网站建设做引流推广的平台
  • 北京小程序制作卓越华网天下百度seo怎么样优化
  • 怎么样做网站或产品推广网络营销五个主要手段
  • 服务器做网站好郑州网站制作公司哪家好
  • 网站制作郑州网站制作关键词优化排名怎么做
  • 晋江建设银行招聘网站裤子seo关键词
  • 福州云建站模版佛山抖音seo
  • 视频代做网站推广宣传
  • 科技公司网站模板seo推广主要做什么
  • 为什么选择做网站编辑推广普通话奋进新征程演讲稿
  • 学习java可以做网站吗世界球队最新排名
  • 中国建设银行网站首页企业网银沈阳全网推广公司哪家好
  • 网站空间不足灰色项目推广渠道
  • 利用菜刀软件xise做网站劫持郑州网站推广公司
  • 公司网站开发比选如何制作企业网站
  • 网站推广的方案设计怎么写推广优化seo
  • 网站负责人备案采集照株洲今日头条新闻
  • 怎样做软件网站建设新冠病毒最新消息
  • 网络营销的特点包含()。搜索引擎seo外包
  • 电子商务网站建设与管理相关文献宣传推广
  • 代做动画毕业设计的网站云服务器免费
  • wordpress后台菜单管理优化网站推广
  • 网站重要性优化关键词具体要怎么做
  • 网站怎么加载图片做logo阿里云建站费用
  • wordpress post page株洲seo优化报价
  • iis7 部署静态网站赣州是哪个省
  • 网站建设图文河南推广网站的公司
  • 网站建设的具体布局销售课程培训视频教程
  • 网店装修的目标不包括巩义网站优化公司