Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
Leetcode Solution (Python)
class Solution:
def strStr(self, haystack: str, needle: str) -> int:
n = len(needle)
#print(needle)
for i in range(0,len(haystack)-n+1):
substr = haystack[i:i+n]
#print(substr)
if substr == needle:
return i
return -1
Elements of Programming Interviews in Python: The Insiders’ Guide