Implement strStr() LeetCode solution in Python

1
class Solution(object):
2
def strStr(self, haystack, needle):
3
if needle == "":
4
return 0
5
else:
6
return self.search_substring(haystack, needle)
7

8
def search_substring(self, haystack, needle):
9
len_substring = len(needle)
10
for i in range(len(haystack)):
11
if haystack[i : i + len_substring] == needle:
12
return i
13
return -1

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0