[Solution with Javascript](https://github.com/tangweikun/leetcode)


  • 0

    Leetcode Solution with Javascript

    var strStr = function(haystack, needle) {
      const haystackLen = haystack.length
      const needleLen = needle.length
    
      for (let i = 0; i <= haystackLen - needleLen; i++) {
        if (haystack.substring(i, i + needleLen) === needle) {
          return i
        }
      }
    
      return -1
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.