/**
* @param {string} haystack
* @param {string} needle
* @return {number}
*/
var strStr = function(haystack, needle) {
var start = "";
for (var i = 0; i < needle.length - 1 ; i++) {
start += haystack[i];
}
for (var i = needle.length - 1 ; i < haystack.length ; i++) {
start += haystack[i];
if (start == needle) {
return i - needle.length + 1;
}
start = start.slice(1);
}
return -1;
};
No comments:
Post a Comment