class Solution {
public:
int strStr(string haystack, string needle) {
if(haystack.size()<needle.size())
{
return -1;
}
for(int i = 0;i < haystack.size()-needle.size()+1;i++)
{
if(haystack.substr(i,needle.size()) == needle)
{
return i;
}
}
return -1;
}
};
class Solution {
public:
int strStr(string haystack, string needle) {
if(haystack.size()<needle.size())
{
return -1;
}
for(int i = 0;i < haystack.size()-needle.size()+1;i++)
{
int k = 0;
int j = i;
while(k<needle.size() && haystack[j] == needle[k])
{
k++;
j++;
}
if(k == needle.size())
{
return i;
}
}
return -1;
}
};