Skip to content

Commit 5abaf75

Browse files
Update and rename NeedleInHayStack.cpp to easy-28-index_of_first_occurrence_in_string.cpp
1 parent 8342f13 commit 5abaf75

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Codes/NeedleInHayStack.cpp renamed to Codes/easy-28-index_of_first_occurrence_in_string.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
// You are given two strings needle and haystack.
2+
// Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
3+
4+
5+
6+
// Example 1:
7+
8+
// Input: haystack = "sadbutsad", needle = "sad"
9+
// Output: 0
10+
// Explanation: "sad" occurs at index 0 and 6.
11+
// The first occurrence is at index 0, so we return 0.
12+
13+
// Example 2:
14+
15+
// Input: haystack = "leetcode", needle = "leeto"
16+
// Output: -1
17+
// Explanation: "leeto" did not occur in "leetcode", so we return -1.
18+
19+
120
class Solution {
221
public:
322
int strStr(string haystack, string needle) {

0 commit comments

Comments
 (0)