From 936c2d135f4746c6e1c3bc6891b068ea16efe5d0 Mon Sep 17 00:00:00 2001 From: vi Date: Wed, 14 Oct 2026 18:42:29 +0300 Subject: [PATCH 1/4] add C++/28_first_occurence_in_a_string.cpp with the solution for 28th Leetcod task --- C++/28_first_occurence_in_a_string.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 C++/28_first_occurence_in_a_string.cpp diff --git a/C++/28_first_occurence_in_a_string.cpp b/C++/28_first_occurence_in_a_string.cpp new file mode 100644 index 0000000..d507c36 --- /dev/null +++ b/C++/28_first_occurence_in_a_string.cpp @@ -0,0 +1,26 @@ +/** + * easy difficulty + * runtime: 0ms + * beats 100% + * + * memory: 8.85mb + * beats 99.68% + */ + +class Solution { +public: + /** + * @brief a function will return the index of the first occurence of + * a string in the main string + * @param haystack is the main string that the search will be applied to + * @param needle is the string that the function will search for + * @return the index of the first occurence of 'needle' in 'haystack' if + * found ; std::string::npos (or -1) otherwise + */ + constexpr inline int strStr(const string& haystack, const string& needle) noexcept { + // using built in functions to find the index of the + // first occurence of the 'needle' in the 'haystack' + // and if 'needle' isn't present, it will return std::string::npos (-1) + return haystack.find(needle); + } +}; From da31bc14d06f56ce5304f5069a00c1be7f2fdf31 Mon Sep 17 00:00:00 2001 From: vi Date: Wed, 14 Oct 2026 18:48:37 +0300 Subject: [PATCH 2/4] edit README.md to include the 28th task in the Two Pointers category --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f509980..7788767 100644 --- a/README.md +++ b/README.md @@ -294,9 +294,10 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | --- | --------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | ---------------------- | ------------------ | ---------- | ----------- | ---------------- | | 005 | [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/) | [Python](./Python/5_LongestPalindromicSubstring.py)
[JavaScript](./JavaScript/5.Longest-Palindromic-Substring.js) | _O(N^2)_
_O(N^2)_ | _O(N)_
_O(1)_ | Medium | | Expand the Wings | | 4 | [Median of Two Sorted Arrays](https://leetcode.com/problems/median-of-two-sorted-arrays/) | [Java](./Java/median-of-two-sorted-arrays.java) | _O(log(min(m,n)))_ | _O(1)_ | Hard | | | -| 845 | [Longest Mountain in Array](https://leetcode.com/problems/longest-mountain-in-array/) | [C++](./C++/Longest-Mountain-in-Array.cpp) | _O(N)_ | _O(1)_ | Medium | Two Pointer | +| 845 | [Longest Mountain in Array](https://leetcode.com/problems/longest-mountain-in-array/) | [C++](./C++/Longest-Mountain-in-Array.cpp) | _O(N)_ | _O(1)_ | Medium | Two Pointer | | | 015 | [3 Sum](https://leetcode.com/problems/3sum/) | [C++](./C++/3sum.cpp) | _O(N)_ | _O(1)_ | Medium | Two Pointer | | | 021 | [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | [C++](./C++/Longest-Mountain-in-Array.cpp) | _O(N)_ | _O(1)_ | Easy | Two Pointer | | +| 28 | [Find the Index of the First Occurence in a String](https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string) | [C++](./C++/28_first_occurenct_in_a_string.cpp) | _O(1)_ | _O(1)_ | Easy | Two Pointer | |
From a00a415e904a35eb210eaa6392e4d4e5a050da84 Mon Sep 17 00:00:00 2001 From: vi Date: Wed, 14 Oct 2026 19:22:14 +0300 Subject: [PATCH 3/4] rename the 28_first_occurence_in_a_string.cpp to 28_first_occurence_in_a_string to correct the speaking of the occurrence word --- ...urence_in_a_string.cpp => 28_first_occurrence_in_a_string.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename C++/{28_first_occurence_in_a_string.cpp => 28_first_occurrence_in_a_string.cpp} (100%) diff --git a/C++/28_first_occurence_in_a_string.cpp b/C++/28_first_occurrence_in_a_string.cpp similarity index 100% rename from C++/28_first_occurence_in_a_string.cpp rename to C++/28_first_occurrence_in_a_string.cpp From 96d6be78d41b5db0ee94064515e1eac6311575ab Mon Sep 17 00:00:00 2001 From: vi Date: Wed, 14 Oct 2026 19:40:39 +0300 Subject: [PATCH 4/4] rename the file with solution for the 28th task in README.md to suit the current name of the solution file --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7788767..2bbe043 100644 --- a/README.md +++ b/README.md @@ -297,7 +297,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 845 | [Longest Mountain in Array](https://leetcode.com/problems/longest-mountain-in-array/) | [C++](./C++/Longest-Mountain-in-Array.cpp) | _O(N)_ | _O(1)_ | Medium | Two Pointer | | | 015 | [3 Sum](https://leetcode.com/problems/3sum/) | [C++](./C++/3sum.cpp) | _O(N)_ | _O(1)_ | Medium | Two Pointer | | | 021 | [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | [C++](./C++/Longest-Mountain-in-Array.cpp) | _O(N)_ | _O(1)_ | Easy | Two Pointer | | -| 28 | [Find the Index of the First Occurence in a String](https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string) | [C++](./C++/28_first_occurenct_in_a_string.cpp) | _O(1)_ | _O(1)_ | Easy | Two Pointer | | +| 28 | [Find the Index of the First Occurence in a String](https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string) | [C++](./C++/28_first_occurrence_in_a_string.cpp) | _O(1)_ | _O(1)_ | Easy | Two Pointer | |