LeetCode 28. Find the Index of the First Occurrence in a String
October 31, 2024
This was an easy problem.
Solution
class Solution:
def strStr(self, haystack: str, needle: str) -> int:
for j in range(len(haystack)):
if haystack[j:j + len(needle)] == needle:
return j
return -1
O(n) = n