Simple C++ Solution using substr() function


#1
int Solution::strStr(const string A, const string B) {
int ans=-1;
int n=A.size(),m=B.size();

for(int i=0;i<n;i++)
{
    if(A[i]==B[0])
    {
        if(A.substr(i,m)==B) return i;
    }
}

return -1;
}

#2

but they asked not to use standard library string functions for this question.