超时
class Solution {
public:
int strStr(string haystack, string needle) {
if(needle == "")
return 0;
int m = haystack.size();
int n = needle.size();
for(int i = 0; i < m; i++){
int j = 0;
for(; j < n; j++){
if(i >=m || haystack[i+j] != needle[j])
break;
}
if(j == n)
return i;
}
return -1;
}
};
KMP算法,以后再看
https://leetcode-cn.com/problems/implement-strstr/solution/zhe-ke-neng-shi-quan-wang-zui-xi-de-kmp-8zl57/