feat(Go-Tool):

2021/03/02: 新增字符串匹配 暴力匹配、KMP匹配、SunDay匹配算法
            2021/03/02: 修复Rand包随机获取方法
This commit is contained in:
Huangzj
2021-03-02 13:33:07 +08:00
parent 74dd19c675
commit dc5d924a2c
13 changed files with 385 additions and 7 deletions
+32
View File
@@ -0,0 +1,32 @@
/*
* @Author : huangzj
* @Time : 2021/2/25 11:11
* @Description
*/
package stringMatch
func ViolentMatch(allString, match string) int {
i := 0
j := 0
sLength := len(allString)
mLenght := len(match)
for i < sLength && j < mLenght {
//当前字符如果匹配,继续匹配下一个字符,坐标移动
if allString[i] == match[j] {
j++
i++
} else {
//如果字符不匹配,match从头开始,被匹配的字符串从之前匹配的下一个字符开始,坐标修改
i = i - j + 1
j = 0
}
}
if j == len(match) {
return i - j
}
return -1
}