class Solution {
public:
int strStr(string haystack, string needle) {
int n = haystack.size(),m = needle.size();
for(int i = 0;i < n - m + 1;i++)
{
int j = 0;
for(;j < m;j++)
{
if(haystack[i+j] != needle[j])
break;
}
if(j == m)
return i;
}
return -1;
}
};
leetcode28. 实现 strStr()
最新推荐文章于 2022-03-17 12:49:48 发布