Time: 17 ms (82.26%), Space: 13.4 MB (65.37%) - LeetHub

This commit is contained in:
Deven
2023-01-08 09:30:37 -05:00
parent b7f8046484
commit 0f8078a26d
@@ -0,0 +1,19 @@
class Solution(object):
def strStr(self, haystack, needle):
"""
:type haystack: str
:type needle: str
:rtype: int
"""
# Empty needle edge-case
if needle == "":
return 0
index = 0
while index + len(needle) <= len(haystack):
if haystack[index] == needle[0]:
if haystack[index:index+len(needle)] == needle:
return index
index += 1
return -1