Problem List

Find The Index Of The First Occurence In A String

January 30, 2025Go stringseasy

Problem

Performance

Complexity

Go Solution
func strStr(haystack string, needle string) int {
  i:= 0
  for len(needle) <= len(haystack) - i {
    if needle == haystack[i: i+ len(needle)] {
      return i
    }
    i++
  }
  return -1  
}

LeetCode Problem Link