Problems

15. Find the Index of the First Occurrence in a String

EasyStringGoogleMicrosoft

Given strings haystack and needle, return the index of the first occurrence of needle in haystack, or -1 if it is not present.

Example 1:

Input: haystack = "sadbutsad", needle = "sad"
Output: 0

Example 2:

Input: haystack = "leetcode", needle = "leeto"
Output: -1

Constraints:

  • 1 <= haystack.length, needle.length <= 10^4
Core code mode
● Auto-savedLine 1, column 1