From e74923831afb9e41cfa74c120b2d7b70d941321e Mon Sep 17 00:00:00 2001 From: Deven <63876261+devenperez@users.noreply.github.com> Date: Sat, 16 Jul 2022 13:36:55 -0400 Subject: [PATCH] Time: 24 ms (58.55%), Space: 13.4 MB (83.01%) - LeetHub --- 28-implement-strstr/28-implement-strstr.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 28-implement-strstr/28-implement-strstr.py diff --git a/28-implement-strstr/28-implement-strstr.py b/28-implement-strstr/28-implement-strstr.py new file mode 100644 index 0000000..cf42492 --- /dev/null +++ b/28-implement-strstr/28-implement-strstr.py @@ -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 \ No newline at end of file