Skip to content

Commit

Permalink
Time: 0 ms (100.00%), Space: 16.6 MB (48.46%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisTabin committed Nov 3, 2024
1 parent 9fbf401 commit 0977ad3
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution:
def strStr(self, haystack: str, needle: str) -> int:
h_index = 0
n_index = 0
for curr_h_index in range(len(haystack)):
while curr_h_index + h_index < len(haystack) and n_index < len(needle) and haystack[curr_h_index + h_index] == needle[n_index]:
n_index += 1
h_index += 1
if n_index == len(needle):
return curr_h_index
else:
n_index = 0
h_index = 0
return -1

0 comments on commit 0977ad3

Please sign in to comment.