Return the index of the first occurrence of needle in haystack, or -1 if it does not occur. An empty needle occurs at index 0.
For haystack = "sadbutsad" and needle = "sad" the answer is 0; for needle = "leeto" in "leetcode" it is -1.
The starter code compares letter by letter at every start. It is correct but too slow on repetitive texts.
Example 1
Input:
find_needle('sadbutsad', 'sad')
Output:
0
Example 2
Input:
find_needle('leetcode', 'leeto')
Output:
-1
0 <= len(haystack) <= 2000000 <= len(needle) <= 2000No results yet
Run your code to check it against the examples, or submit to run every test.