leetCode:28. Implement strStr()

Example 1:

Input: haystack = "hello", needle = "ll"
Output: 2

Example 2:

Input: haystack = "aaaaa", needle = "bba"
Output: -1
/**
 * @param {string} haystack
 * @param {string} needle
 * @return {number}
 */
var strStr = function(haystack, needle) {
    let num = haystack.indexOf(needle)
    return num;
};

猜你喜欢

转载自www.cnblogs.com/xiyu-8023/p/10418840.html