We’re preparing your current view and syncing the latest data.
Given two strings haystack and needle, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
Two strings, haystack and needle.
An integer representing the starting index of the first occurrence of needle in haystack, or -1 if needle is not found.
0 <= haystack.length, needle.length <= 5 * 10^4
Example 1
Input
haystack = "sadbutsad", needle = "sad"
Output
0
Explanation
The first occurrence of "sad" is at index 0.
Example 2
Input
haystack = "leetcode", needle = "leeto"
Output
-1
Explanation
"leeto" does not occur in "leetcode".