class Solution {
public:
int strStr(string haystack, string needle) {
int res=haystack.find(needle);
if(res!=std::string::npos){
return res;
}else{
return -1;
}
}
};
也可以考虑KMP。
class Solution {
public:
int strStr(string haystack, string needle) {
int res=haystack.find(needle);
if(res!=std::string::npos){
return res;
}else{
return -1;
}
}
};
也可以考虑KMP。