feat(Go-Tool):2021/03/11: 新增Kr、Shift and/or字符串匹配算法

This commit is contained in:
Huangzj
2021-03-11 15:04:41 +08:00
parent 351df675bd
commit ed71f9b607
7 changed files with 182 additions and 5 deletions
+28
View File
@@ -0,0 +1,28 @@
/*
* @Author : huangzj
* @Time : 2021/3/5 13:17
* @Description
*/
package stringMatch
func KarpRabinMatch(allString, modeString string) int {
hashMode := hash(modeString)
for i := 0; i < len(allString)-len(modeString)+1; i++ {
hashKey := hash(allString[i : i+len(modeString)+1])
if hashMode == hashKey {
for j := 0; j < len(modeString); j++ {
if allString[i+j] != modeString[j] {
break
}
}
return i
}
}
return -1
}
func hash(s string) int {
return 1
}