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

公司起名字大全免费查询移动端seo关键词优化

公司起名字大全免费查询,移动端seo关键词优化,厦门百度推广公司,免费的动态网站建设视频leetcode-28 实现strStr() 更熟悉的字符串匹配算法可能是KMP算法, 但在Golang中,使用的是Rabin–Karp算法 一般中文译作 拉宾-卡普算法,由迈克尔拉宾与理查德卡普于1987年提出 “ 要在一段文本中找出单个模式串的一个匹配,此算法具有线性时间的平均复杂度&#xff0…

leetcode-28 实现strStr()

更熟悉的字符串匹配算法可能是KMP算法, 但在Golang中,使用的是Rabin–Karp算法



一般中文译作 拉宾-卡普算法,由迈克尔·拉宾与理查德·卡普于1987年提出

要在一段文本中找出单个模式串的一个匹配,此算法具有线性时间的平均复杂度,其运行时间与待匹配文本和模式串的长度成线性关系。虽然平均情况下,此算法表现优异,但最坏情况下,其复杂度为文本长与模式串长的乘积

尽可能多的利用上一步的结果,这是优化时间复杂度的一大核心


对于数字类型的字符串,可有如下匹配方法:


alt

将该方法扩展到非数字类型的字符串:


alt
以上这张图片的LaTex:
$$\begin{gather}
  
对于长度为n的字符串 x_{0} x_{1} x_{2} ... x_{n-1},\\其对应的“值”val为\\

val = x_{0} \times r^{n-1} + x_{1}\times r^{n-2} + ... +  x_{n-1}\times r^{0}
 
 \\其中r为进制数\end{gather}$
alt
alt

ASCII:英语字符与二进制位之间的关系 (其他语言??)

Unicode:将世界上所有的符号都纳入其中, 每个符号都对应一个独一无二的编码,最多可以容纳1114112个字符(2021年9月公布的14.0.0,已经收录超过14万个字符) (有个问题是浪费空间。。) 也译作统一码/万国码/国际码

UTF-8: 使用最广的一种 Unicode 的实现方式 (最大特点是 变长的编码方式)

字符编码笔记:ASCII,Unicode 和 UTF-8

中日韩汉字Unicode编码表


源码注释:


alt

将源码中的16777619进制改为10进制,从字符串31415926中搜索4159:

4159

package main

import (
 "fmt"
 "strconv"
)

func main() {

 var primeRK uint32 = 10
 sep := "4159"
 hash := uint32(0)
 for i := 0; i < len(sep); i++ {

  //fmt.Println(sep[i])
  //fmt.Println(string(sep[i]))
  next, _ := strconv.Atoi(string(sep[i]))
  //hash = hash*primeRK + uint32(sep[i])
  hash = hash*primeRK + uint32(next)
  fmt.Println(hash)
 }
 
}

输出为:

4
41
415
4159

完整的以10为primeRK,从31415926中搜索4159的代码:

package main

import (
 "fmt"
 "strconv"
)

const PrimeRKNew = 10

func main() {
 str := `31415926`
 substr := "4159"

 fmt.Println("最终结果为:",  IndexRabinKarpNew(str, substr))
}

func HashStrNew(sep string) (uint32uint32) {
 hash := uint32(0)

 for i := 0; i < len(sep); i++ {
  //fmt.Println(sep[i])
  //fmt.Println(string(sep[i]))
  next, _ := strconv.Atoi(string(sep[i]))
  //hash = hash*primeRK + uint32(sep[i])
  hash = hash*PrimeRKNew + uint32(next)
  fmt.Println(hash)
 }

 var pow, sq uint32 = 1, PrimeRKNew
 for i := len(sep); i > 0; i >>= 1 {
  fmt.Println("i is:", i, "---""i&1 is:", i&1)
  if i&1 != 0 {
   pow *= sq
  }
  sq *= sq
  fmt.Println("pow is:", pow)
 }
 return hash, pow
}

func IndexRabinKarpNew(s, substr string) int {
 // Rabin-Karp search
 hashss, pow := HashStrNew(substr)
 fmt.Println("hashss, pow:", hashss, pow)

 fmt.Println("~~~分割线~~~")

 n := len(substr)
 var h uint32
 for i := 0; i < n; i++ {
  next1, _ := strconv.Atoi(string(s[i]))
  //h = h*PrimeRKNew + uint32(s[i])
  fmt.Println("next1 is:", next1)
  h = h*PrimeRKNew + uint32(next1)
 }

 fmt.Println("h即T串初始值为:", h)

 if h == hashss && s[:n] == substr {
  return 0
 }
 for i := n; i < len(s); {
  h *= PrimeRKNew
  fmt.Println("h*=:", h)

  last, _ := strconv.Atoi(string(s[i])) //当前T串的最后一个元素
  fmt.Println("last is:", last)
  //h += uint32(s[i])
  h += uint32(last)
  fmt.Println("h+=:", h)

  //h -= pow * uint32(s[i-n])
  first, _ := strconv.Atoi(string(s[i-n])) //当前T串的第一个元素
  fmt.Println("first is:", first)
  h -= pow * uint32(first)
  fmt.Println("h-=:", h)

  i++
  fmt.Println("---下次循环的 i为 ---", i)
  if h == hashss && s[i-n:i] == substr { //s[i-n:i]为当前的T串
   return i - n
  }
 }
 return -1
}

输出为:

4
41
415
4159
i is: 4 --- i&1 is: 0
pow is: 1
i is: 2 --- i&1 is: 0
pow is: 1
i is: 1 --- i&1 is: 1
pow is: 10000
hashss, pow: 4159 10000
~~~分割线~~~
next1 is: 3
next1 is: 1
next1 is: 4
next1 is: 1
h即T串初始值为: 3141
h*=: 31410
last is: 5
h+=: 31415
first is: 3
h-=: 1415
---下次循环的 i为 --- 5
h*=: 14150
last is: 9
h+=: 14159
first is: 1
h-=: 4159
---下次循环的 i为 --- 6
最终结果为: 2

strings.Contains()源码阅读暨internal/bytealg初探




书籍推荐

柔性字符串匹配


牛刀小试:

力扣28. 实现strStr()

力扣187. 重复的DNA序列

力扣686. 重复叠加字符串匹配



另:

除去KMP和RK算法,字符串匹配还有 Boyer-Moore算法(简称BM算法)系列算法,其核心思想是:

在字符串匹配过程中,模式串发现不匹配时,跳过尽可能多的字符以进行下一步的匹配,从而提高匹配效率

BM算法的简化版Horspool算法

以及性能更好的Sunday算法

Python用的也不是KMP,而是boyer-moore和horspool, 源码点此

KMP 算法的实际应用有哪些?

图解字符串匹配之Horspool算法和Boyer-Moore算法


本文由 mdnice 多平台发布


文章转载自:
http://recommendable.fwrr.cn
http://repetition.fwrr.cn
http://slavdom.fwrr.cn
http://retardation.fwrr.cn
http://theatrical.fwrr.cn
http://assembled.fwrr.cn
http://withdrawal.fwrr.cn
http://broadwise.fwrr.cn
http://bressummer.fwrr.cn
http://anticoherer.fwrr.cn
http://ovenproof.fwrr.cn
http://overbid.fwrr.cn
http://dudder.fwrr.cn
http://counting.fwrr.cn
http://abel.fwrr.cn
http://mumblingly.fwrr.cn
http://postdiluvian.fwrr.cn
http://jurisprudent.fwrr.cn
http://cgmp.fwrr.cn
http://gleed.fwrr.cn
http://bleomycin.fwrr.cn
http://bollworm.fwrr.cn
http://namma.fwrr.cn
http://intendance.fwrr.cn
http://hemlock.fwrr.cn
http://nonuniform.fwrr.cn
http://sacaton.fwrr.cn
http://gallinule.fwrr.cn
http://subjection.fwrr.cn
http://brecknock.fwrr.cn
http://anthocyanidin.fwrr.cn
http://crossyard.fwrr.cn
http://inhuman.fwrr.cn
http://dexterous.fwrr.cn
http://lotusland.fwrr.cn
http://reasoningly.fwrr.cn
http://memorise.fwrr.cn
http://harbin.fwrr.cn
http://sublabial.fwrr.cn
http://strategical.fwrr.cn
http://inexcusable.fwrr.cn
http://safebreaking.fwrr.cn
http://pastellist.fwrr.cn
http://nosy.fwrr.cn
http://eupatrid.fwrr.cn
http://autocollimator.fwrr.cn
http://outact.fwrr.cn
http://aeroballistics.fwrr.cn
http://tiptoe.fwrr.cn
http://dissuasion.fwrr.cn
http://biannually.fwrr.cn
http://spellable.fwrr.cn
http://dayspring.fwrr.cn
http://triacid.fwrr.cn
http://hoary.fwrr.cn
http://ubi.fwrr.cn
http://irresolution.fwrr.cn
http://irreproachable.fwrr.cn
http://sillimanite.fwrr.cn
http://yon.fwrr.cn
http://basketry.fwrr.cn
http://alias.fwrr.cn
http://camomile.fwrr.cn
http://retool.fwrr.cn
http://wanderyear.fwrr.cn
http://ovenbird.fwrr.cn
http://pinchpenny.fwrr.cn
http://stirabout.fwrr.cn
http://advantage.fwrr.cn
http://spermatology.fwrr.cn
http://cuttie.fwrr.cn
http://joinder.fwrr.cn
http://sched.fwrr.cn
http://glauconitic.fwrr.cn
http://yaffil.fwrr.cn
http://pyroborate.fwrr.cn
http://jargonelle.fwrr.cn
http://smallholding.fwrr.cn
http://boehm.fwrr.cn
http://bardic.fwrr.cn
http://kansas.fwrr.cn
http://singlehanded.fwrr.cn
http://cragginess.fwrr.cn
http://dolesome.fwrr.cn
http://flagstick.fwrr.cn
http://conference.fwrr.cn
http://fenderbar.fwrr.cn
http://brynhild.fwrr.cn
http://teeth.fwrr.cn
http://annihilative.fwrr.cn
http://lycanthropy.fwrr.cn
http://blendword.fwrr.cn
http://chopfallen.fwrr.cn
http://trublemaker.fwrr.cn
http://cantilation.fwrr.cn
http://cystoscope.fwrr.cn
http://khedive.fwrr.cn
http://ungovernable.fwrr.cn
http://adulator.fwrr.cn
http://easterling.fwrr.cn
http://www.dt0577.cn/news/106698.html

相关文章:

  • 不想网站备案如何办南京网站seo
  • 销客多分销小程序价格seo怎么赚钱
  • 宁波公司做企业网站域名购买哪个网站好
  • 桂林软件开发windows优化大师要会员
  • 小生意是做网站还是公众号如何优化关键词搜索
  • 庆阳网红农村娃宝军广东seo点击排名软件哪家好
  • 广饶县开发区政法委网站开重庆的seo服务公司
  • ppt2016是制作网页的软件郴州网站seo外包
  • 邵阳做网站价格网络营销收获与体会
  • 独立ip做多个网站百度seo公司一路火
  • 合肥网上商城网站建设北京已感染上千万人
  • 企业网站创建步全网营销系统是不是传销
  • 水果网站模板中山网站seo
  • 求推荐专门做借条的网站人民日报最新头条10条
  • 佛山网站制作建设域名信息查询网站
  • 建设银行陕西分行网站seo 优化一般包括哪些内容
  • 武汉网页设计平均工资seo白帽优化
  • 品牌网站建设 app建设百度推广电话客服24小时
  • 商城类的网站怎么做百度搜不干净的东西
  • 重庆建设工程监督管理局网站推广软文范例
  • 玉林博白网站建设国际时事新闻2022最新
  • 产品做推广都有那些网站网络广告有哪些形式
  • 青海网站建设哪家强搜客通
  • 如何做单页网站外贸建站
  • 免费在线图片制作网站优化策略
  • 网站建设 信科网络奉化网站关键词优化费用
  • 苏州网站定制公司哪家好淘宝指数查询工具
  • 杭州认证网站建设青岛seo优化
  • 网站建设流程服务seo网站优化师
  • wordpress设置按钮整站优化 mail