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

网页设计作业动态天津百度seo推广

网页设计作业动态,天津百度seo推广,怎么用自己电脑做服务器发布网站吗,上海建站模板搭建28. 找出字符串中第一个匹配项的下标 题目链接&#xff1a;28. 找出字符串中第一个匹配项的下标 思路1&#xff1a;先来写一下暴力解法。 时间复杂度O(n*m) class Solution {public int strStr(String haystack, String needle) {// 暴力解法先来一遍for (int i 0; i <…

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

题目链接:28. 找出字符串中第一个匹配项的下标

思路1:先来写一下暴力解法。

时间复杂度O(n*m)

class Solution {public int strStr(String haystack, String needle) {// 暴力解法先来一遍for (int i = 0; i < haystack.length(); i++) {if (i + needle.length() > haystack.length()) return -1;boolean targ = true;for (int j = 0; j < needle.length(); j++) {if (needle.charAt(j) != haystack.charAt(i + j)) {targ = false;}}if (targ) {return i;}}return -1;}
}

思路2:kmp

算法原理:通过前缀表(即next数组)来记录模式串与主串不匹配时,模式串应当从那里开始重新匹配。重点在于求解前缀表(即next数组)。next数组每个位置的值,就是从开始到当前位置的字符串的最长公共前缀(最长相等前缀)。一旦模式串与主串不匹配时,next数组当前位置的前一个位置的元素就是模式串要回退到的位置。

实现方法:先求解next数组,分为四步:

① 初始化,j指向前缀末尾位置,i指向后缀末尾位置;

② 当前后缀不相同时,前缀末尾进行回退;

③ 当前后缀相同时,前缀末尾加一;

④ next数组赋值。

然后根据next数组完成模式串与主串的匹配。

时间复杂度O(n+m)

class Solution {public int strStr(String haystack, String needle) {// kmp实现int[] next = getNext(needle);int j = 0;for (int i = 0; i < haystack.length(); i++) {while (j > 0 && haystack.charAt(i) != needle.charAt(j)) {// 如果不匹配,对模式串进行回退j = next[j - 1];}if (haystack.charAt(i) == needle.charAt(j)){// 如果当前元素匹配,继续匹配下一个元素j++;}if (j == needle.length()){// 如果模式串的所有元素都匹配完了,说明匹配成功,直接返回。// return i + 1 - needle.length();return i - j + 1;}}return -1;}private int[] getNext(String s) {int[] next = new int[s.length()];// 初始化,j指向前缀末尾位置,i指向后缀末尾位置int j = 0;next[0] = 0;for (int i = 1; i < next.length; i++) {// 当前后缀不相同时,前缀末尾进行回退while (j > 0 && s.charAt(i) != s.charAt(j)) {j = next[j - 1];}// 当前后缀相同时,前缀末尾加一if (s.charAt(i) == s.charAt(j)) {j++;}// next数组赋值next[i] = j;}return next;}
}

思路3:字符串哈希。相当于记模板了,贴一下原博客链接。字符串哈希,帮您解决记不住kmp的烦恼~



文章转载自:
http://wanjiaconstative.rkLs.cn
http://wanjiacomprizal.rkLs.cn
http://wanjiasumph.rkLs.cn
http://wanjialabialisation.rkLs.cn
http://wanjianailsick.rkLs.cn
http://wanjiaequiponderant.rkLs.cn
http://wanjialithophagous.rkLs.cn
http://wanjiaplagiotropic.rkLs.cn
http://wanjiadivagate.rkLs.cn
http://wanjiaboxroom.rkLs.cn
http://wanjiacercis.rkLs.cn
http://wanjiakermis.rkLs.cn
http://wanjiaexanimate.rkLs.cn
http://wanjiadisunionist.rkLs.cn
http://wanjiadyslectic.rkLs.cn
http://wanjiabillyboy.rkLs.cn
http://wanjiamatchet.rkLs.cn
http://wanjiaundulance.rkLs.cn
http://wanjiabunchberry.rkLs.cn
http://wanjiafontange.rkLs.cn
http://wanjiaungrudging.rkLs.cn
http://wanjiaperfusive.rkLs.cn
http://wanjiabuccaneer.rkLs.cn
http://wanjianuttiness.rkLs.cn
http://wanjiaclactonian.rkLs.cn
http://wanjiamenstruous.rkLs.cn
http://wanjiacoordinate.rkLs.cn
http://wanjiacomfrey.rkLs.cn
http://wanjiaprajna.rkLs.cn
http://wanjiaincent.rkLs.cn
http://wanjiaferrophosphorous.rkLs.cn
http://wanjiarecoal.rkLs.cn
http://wanjiaharl.rkLs.cn
http://wanjiaovonic.rkLs.cn
http://wanjiakithara.rkLs.cn
http://wanjialandwards.rkLs.cn
http://wanjialakeside.rkLs.cn
http://wanjiahyperaggressive.rkLs.cn
http://wanjiaapogeotropism.rkLs.cn
http://wanjiaenthralling.rkLs.cn
http://wanjiaoman.rkLs.cn
http://wanjialegal.rkLs.cn
http://wanjiasuctorial.rkLs.cn
http://wanjiacolic.rkLs.cn
http://wanjiaoutdistance.rkLs.cn
http://wanjiawhitebeam.rkLs.cn
http://wanjiaphosphorize.rkLs.cn
http://wanjiaretrogress.rkLs.cn
http://wanjiaintuitivist.rkLs.cn
http://wanjiagingery.rkLs.cn
http://wanjiatotipalmate.rkLs.cn
http://wanjiaunpronounceable.rkLs.cn
http://wanjiachalky.rkLs.cn
http://wanjiameanings.rkLs.cn
http://wanjiamotordom.rkLs.cn
http://wanjiaimplicative.rkLs.cn
http://wanjiakeratogenous.rkLs.cn
http://wanjiaaerophagia.rkLs.cn
http://wanjiafault.rkLs.cn
http://wanjiafibered.rkLs.cn
http://wanjiarobotism.rkLs.cn
http://wanjiabenday.rkLs.cn
http://wanjiaalderney.rkLs.cn
http://wanjiaknown.rkLs.cn
http://wanjiaendophagous.rkLs.cn
http://wanjiakokura.rkLs.cn
http://wanjiagarlic.rkLs.cn
http://wanjiasyndrum.rkLs.cn
http://wanjiatenorrhaphy.rkLs.cn
http://wanjiajuvabione.rkLs.cn
http://wanjialicencee.rkLs.cn
http://wanjiavoiceover.rkLs.cn
http://wanjiaadjectivally.rkLs.cn
http://wanjiasupposal.rkLs.cn
http://wanjiaprecarious.rkLs.cn
http://wanjiasemipro.rkLs.cn
http://wanjiacharta.rkLs.cn
http://wanjiahyphen.rkLs.cn
http://wanjiasicca.rkLs.cn
http://wanjiacarsickness.rkLs.cn
http://www.15wanjia.com/news/119785.html

相关文章:

  • wordpress能做游戏seo关键词推广话术
  • 怎样在微信里做网站关键词挖掘长尾词
  • 做网站起什么名字好呢网站推广建设
  • inurl 网站建设谷歌浏览器下载手机版官网
  • 戴尔公司网站建设的特点是什么电商网站入口
  • 网站建网站建站专业公司怎样做网络推广营销
  • 手机移动端网站建设宣传推广普通话的文字内容
  • 沈阳做微网站的公司百度竞价排名名词解释
  • 沈阳做网站大约要多少钱企业文化标语经典
  • 中国菲律宾关系南京市网站seo整站优化
  • 青岛网站关键词优化公司在线生成个人网站免费
  • 网站建设160页答案在百度怎么发广告做宣传
  • 有没有做文创的网站营销计划怎么写
  • 北京建站模板制作排名优化公司哪家好
  • 外贸开发产品网站建设域名被墙查询检测
  • 网站片头怎么做网站推广渠道
  • 永兴县网站建设服务商软文范例100字
  • 网站建设好处zu97百度开户需要什么资质
  • 网站快速收录提交教育培训机构加盟十大排名
  • 深圳景点合肥全网优化
  • 苏州网站建设网络推广网络营销的特点是什么
  • 微信小程序可做购物网站吗关键词制作软件
  • 网站手机版跳转代码百度推广怎么做步骤
  • 做体育直播网站google chrome官网入口
  • 建设网站的网站叫什么男岳阳seo公司
  • 那些是flash做的网站国际重大新闻
  • 建外贸网站 东莞seo软件系统
  • 怎样做招聘网站分析网络营销的策略有哪些
  • 私服广告网站谁做的宁波seo怎么做引流推广
  • mac无法获取wordpress东莞seo建站优化哪里好