From 127c2a32f4f985284c17dd83a6b6d6455c059077 Mon Sep 17 00:00:00 2001 From: Kiril Kovachev Date: Fri, 8 Mar 2024 17:21:24 +0000 Subject: [PATCH] Solved 28. Find the Index of the First Occurrence in a String --- ...d_array.py => 26_remove_duplicates_from_sorted_array.py} | 0 python/{remove_element.py => 27_remove_element.py} | 0 .../28_find_the_index_of_the_first_occurrence_in_a_string | 6 ++++++ ... 3065_minimum_operations_to_exceed_threshold_value_i.py} | 0 ...3066_minimum_operations_to_exceed_threshold_value_ii.py} | 0 5 files changed, 6 insertions(+) rename python/{remove_duplicates_from_sorted_array.py => 26_remove_duplicates_from_sorted_array.py} (100%) rename python/{remove_element.py => 27_remove_element.py} (100%) create mode 100644 python/28_find_the_index_of_the_first_occurrence_in_a_string rename python/{minimum_operations_to_exceed_threshold_value_i.py => 3065_minimum_operations_to_exceed_threshold_value_i.py} (100%) rename python/{minimum_operations_to_exceed_threshold_value_ii.py => 3066_minimum_operations_to_exceed_threshold_value_ii.py} (100%) diff --git a/python/remove_duplicates_from_sorted_array.py b/python/26_remove_duplicates_from_sorted_array.py similarity index 100% rename from python/remove_duplicates_from_sorted_array.py rename to python/26_remove_duplicates_from_sorted_array.py diff --git a/python/remove_element.py b/python/27_remove_element.py similarity index 100% rename from python/remove_element.py rename to python/27_remove_element.py diff --git a/python/28_find_the_index_of_the_first_occurrence_in_a_string b/python/28_find_the_index_of_the_first_occurrence_in_a_string new file mode 100644 index 0000000..d843ed9 --- /dev/null +++ b/python/28_find_the_index_of_the_first_occurrence_in_a_string @@ -0,0 +1,6 @@ +class Solution: + def strStr(self, haystack: str, needle: str) -> int: + for i in range(len(haystack)): + if haystack[i:i+len(needle)] == needle: + return i + return -1 diff --git a/python/minimum_operations_to_exceed_threshold_value_i.py b/python/3065_minimum_operations_to_exceed_threshold_value_i.py similarity index 100% rename from python/minimum_operations_to_exceed_threshold_value_i.py rename to python/3065_minimum_operations_to_exceed_threshold_value_i.py diff --git a/python/minimum_operations_to_exceed_threshold_value_ii.py b/python/3066_minimum_operations_to_exceed_threshold_value_ii.py similarity index 100% rename from python/minimum_operations_to_exceed_threshold_value_ii.py rename to python/3066_minimum_operations_to_exceed_threshold_value_ii.py