Please Tell Error in this code, used kmp array,


#1

int Solution::strStr(const string A, const string B) {

int n = A.size();
int m = B.size();
if(n==0 || m==0)
    return -1;
int lps[m];
int i=0;
int j=1;
lps[0]=0;
while(j<m){
    
    if(B[i]!=B[j])
    {
        lps[j]= lps[j-1] ;
        j++;
        
    }
    else if(B[i]==B[j]){
        lps[j]= lps[j-1] +1;
        i++;
        j++;
    }
    
}

lps[m-1]=0;


 i=0;
 j=0;
int start=-1;
while(j<m && i<n){
    if(A[i]==B[j]){
        if(start ==-1)
            start = i;
        i++;
        j++;
        
    }
    else if(A[i]!=B[j] && j==0){
        i++;
        start = -1;
    }
    else if(A[i]!= B[j] && j!=0){
        j= lps[j-1];
        start = -1;
    }
    
}

if(i==n && j<m){
    return -1;
}
return start;

}