Javascript Solution


  • 0
    T
    var strStr = function(haystack, needle) {
      var needleLength = needle.length
      var haystackLength = haystack.length
    
      if(needle === '' && haystack === '' ){
        return 0
      }
    
      for(var i=0; i < haystack.length; i++){
        if (haystack.substr(i, needleLength) === 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.