双指针寻找小字符串在长字符串出现的首次索引值
var strStr = function(haystack, needle) {
var L = needle.length;
var n = haystack.length;
if(L === 0) return 0;
var pn = 0;
while(pn < n-L+1){
while(pn < n-L+1 && haystack[pn] != needle[0]) ++pn;
var curlen = 0;
var pL = 0;
while(pL<L&&pn<n && haystack[pn] === needle[pL]){
++pn;
++pL;
++curlen;
}
if(curlen === L ) return pn-L;
pn=pn-curlen +1;
}
return -1;
};
var s = "popop";
var p = "op";
console.log(strStr(s,p));