parent
824d27ae5e
commit
2568258f28
@ -0,0 +1,18 @@
|
|||||||
|
// KMP 算法实例
|
||||||
|
function kmpSearch(str, pattern) {
|
||||||
|
// 生成 next 数组
|
||||||
|
function getNext(pattern) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const next = getNext(pattern);
|
||||||
|
let i = 0;
|
||||||
|
let j = 0;
|
||||||
|
while (i < str.length && j < pattern.length) {
|
||||||
|
if (j === -1 || str[i] === pattern[j]) {
|
||||||
|
i++;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue