class Solution:
def strStr(self, haystack: str, needle: str) -> int:
if needle not in haystack:
return -1
i = 0
if haystack==needle:
return 0
while i<len(haystack):
if haystack[i] == needle[0]:
for j in range(len(needle)):
if i+j>=len(haystack):
return -1
if haystack[i+j] != needle[j]:
break
elif j == len(needle)-1 and haystack[i+j] == needle[j]:
return i
i+= 1
return -1