Skip to content

Commit b2f884c

Browse files
committed
Time: 0 ms (100.00%), Space: 6.3 MB (29.81%) - LeetHub
1 parent e54ebee commit b2f884c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
int strStr(string haystack, string needle) {
4+
int n = haystack.size();
5+
int m = needle.size();
6+
int x = 0;
7+
for(int i = 0; i < n; i++)
8+
{
9+
if(haystack[i] == needle[x]) x++;
10+
else
11+
{
12+
i = i - x;
13+
x = 0;
14+
}
15+
if(x == m) return i - x + 1;
16+
}
17+
return -1;
18+
}
19+
};

0 commit comments

Comments
 (0)