28. Implement strStr()
Leetcode
題目
è§£ç”
var strStr = function(haystack, needle) {
if(needle === "") return 0;
for(let i=0; i<haystack.length-needle.length+1; i++) {
let matchIndex = i;
let j = 0;
while(j < needle.length && haystack[matchIndex] === needle[j]) {
matchIndex++;
j++;
}
if (j === needle.length) return i;
}
return -1;
};測資
Last updated