KMP算法的JS实现

talk is cheap,show me the code:

function kmpGetStrPartMatchValue(str) {
    var prefix = [];
    var suffix = [];
    var partMatch = [];
    for(var i=0;i0 && partMatchValue[m-1] > 0){
                    m = partMatchValue[m-1]-1;
                } else {
                    break;
                }
            }
        }
        if(result){
            break;
        }
    }
    return result;
}
var s = "BBC ABCDAB ABCDABDDABDE";
var t = "ABCDABD";
console.log(kmpGetStrPartMatchValue(t));//[0, 0, 0, 0, 1, 2, 0]
console.log(KMP(s,t));//11

参考链接:

阮一峰-字符串匹配的KMP算法
[KMP算法的JavaScript实现
]

你可能感兴趣的:(KMP算法的JS实现)