Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions C++/28_first_occurrence_in_a_string.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
};
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) <br> [JavaScript](./JavaScript/5.Longest-Palindromic-Substring.js) | _O(N^2)_ <br> _O(N^2)_ | _O(N)_ <br> _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_occurrence_in_a_string.cpp) | _O(1)_ | _O(1)_ | Easy | Two Pointer | |


<br/>
Expand Down
Loading