Naive Algorithm in C++


#1
int Solution::strStr(const string A, const string B) {
    if(B == "" || A == "")
        return -1;
    
    int n = A.size();
    int m = B.size();
    
    for(int i = 0; i < n-m+1; i++){
        int f = 1;
        for(int j = 0; j < m; j++){
            if(B[j] != A[i+j]){
                f = 0;
                break;
            }
        }
        if(f)
            return i;
    }
    
    return -1;
}