LeetCode 筆記 - 28. Implement strStr() Posted on 2022-05-09題目在此 28. Implement strStr()實作 C 語言的 strstr()解題思維不解釋,直接開幹Time complexity: O(n)程式碼1234567891011121314151617class Solution: def strStr(self, haystack: str, needle: str) -> int: if not haystack or not needle: return 0 main_length = len(haystack) check_length = len(needle) if main_length == 1: return 0 for i in range(main_length): if haystack[i:i + check_length] == needle: return i return -1也許你也會想看看LeetCode 筆記 - 43. Multiply StringsLeetCode 筆記 - 18. 4SumLeetCode 筆記 - 29. Divide Two Integers