We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 036f65f commit 5a16320Copy full SHA for 5a16320
Python/implement-strstr.py
@@ -14,17 +14,17 @@ class Solution:
14
# @param needle, a string
15
# @return a string or None
16
def strStr(self, haystack, needle):
17
+ if not needle:
18
+ return 0
19
+
20
if len(haystack) < len(needle):
- return None
-
- if len(needle) == 0:
21
- return haystack
+ return -1
22
23
i = self.KMP(haystack, needle)
24
if i > -1:
25
- return haystack[i:]
+ return i
26
else:
27
28
29
def KMP(self, text, pattern):
30
prefix = self.getPrefix(pattern)
0 commit comments