class Solution: def strStr(self, haystack: str, needle: str) -> int: for i in range(len(haystack) - len(needle) + 1): # 判断needle是否属于haystack中的一部分 if haystack[i:i+len(needle)] == needle: return i return -1