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