mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-13 14:57:08 +00:00
19 lines
515 B
Python
19 lines
515 B
Python
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 |