Easy O(n) solution without KMP


#1

int Solution::strStr(const string A, const string B) {
if(B.length() == 0)
return -1;
if(A.length() == 0)
return -1;

size_t f = A.find(B);

if(f == string::npos)
{
    return -1;
}
else
{
    return int(f);
}

}


#2
int Solution::strStr(const string A, const string B) 
{
    return A.find(B);
}

Same solution but more concise :wink: