diff --git a/28-implement-strstr/28-implement-strstr.py b/28-implement-strstr/28-implement-strstr.py deleted file mode 100644 index cf42492..0000000 --- a/28-implement-strstr/28-implement-strstr.py +++ /dev/null @@ -1,19 +0,0 @@ -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 diff --git a/28-implement-strstr/README.md b/28-implement-strstr/README.md deleted file mode 100644 index 8691640..0000000 --- a/28-implement-strstr/README.md +++ /dev/null @@ -1,31 +0,0 @@ -
Implement strStr().
- -Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
Clarification:
- -What should we return when needle is an empty string? This is a great question to ask during an interview.
For the purpose of this problem, we will return 0 when needle is an empty string. This is consistent to C's strstr() and Java's indexOf().
-
Example 1:
- -Input: haystack = "hello", needle = "ll" -Output: 2 -- -
Example 2:
- -Input: haystack = "aaaaa", needle = "bba" -Output: -1 -- -
-
Constraints:
- -1 <= haystack.length, needle.length <= 104haystack and needle consist of only lowercase English characters.