Time: 24 ms (58.55%), Space: 13.4 MB (83.01%) - LeetHub

This commit is contained in:
Deven
2022-07-16 13:36:55 -04:00
parent 9f981da303
commit e74923831a
@@ -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