commit b1449e80d4e7d7f06966fce6edfe775cbd64f49e
parent 8c9a3b0fc07b26573deb58c63cedc3f0653a8bc4
Author: Andrew Laack <andrew@laack.co>
Date: Wed, 2 Jul 2025 10:18:38 -0500
Completed find-the-index-of-the-first-occurrence-in-a-string/find-the-iV2.py
Diffstat:
1 file changed, 13 insertions(+), 0 deletions(-)
diff --git a/find-the-index-of-the-first-occurrence-in-a-string/find-the-iV2.py b/find-the-index-of-the-first-occurrence-in-a-string/find-the-iV2.py
@@ -0,0 +1,13 @@
+class Solution:
+ def strStr(self, haystack: str, needle: str) -> int:
+ for i in range(0, 1 + len(haystack) - len(needle)):
+ if incremental_check(i, needle, haystack):
+ return i
+ return -1
+
+
+def incremental_check(index, needle, haystack):
+ for itr in range(0, len(needle)):
+ if haystack[index + itr] != needle[itr]:
+ return False
+ return True