blob: 4c888c2302235aa4e2056aa1ae617924b293efc8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#include "leetcode.h"
class Solution {
public:
int strStr(string haystack, string needle) {
int m = haystack.size(), n = needle.size();
for (int i = 0; i <= m - n; i++) {
int j;
for (j = 0; j < n; j++)
if (haystack[i + j] != needle[j])
break;
if (j == n)
return i;
}
return -1;
}
};
int main() {}
|