brute_force

2022-12-14 浏览 (688)

brute_force.go 源码

package string

//字符串匹配-BF算法

func BruteForce(text, ptn string) int {
	m, n := len(text), len(ptn)
	if n > m {
		return BruteForce(ptn, text)
	}

	for i := 0; i <= m-n; i++ {
		j := 0
		for j < n && text[i+j] == ptn[j] {
			j++
		}
		if j == n {
			return i
		}
	}
	return -1
}

你可能感兴趣的文章

brute_force_test

isomorphic_strings

longest_common_prefix

  • 所属分类: 后端技术
  • 本文标签: 技术
  • 版权声明: 本文链接 https://seaxiang.com/blog/e13b426c79c34e328c41c3d6edebaf30