Easy understand c code


  • 0
    A
    int repeatedStringMatch(char* A, char* B) {
        int res = 1;
        int alen = strlen(A);
        int blen = strlen(B);
        
        for(int i=0; i<alen; i++)
        {
            if(A[i] == B[0])
            {
                int m = i;
                int flag = 0;
                for(int k=0; k<blen; k++)
                {
                    if(m == alen)
                    {
                        res++; 
                        m=0;
                    }
                    if(A[m] != B[k])
                    {
                        flag=1;
                        break;   
                    }
                    m++;   
                }
                if(flag == 0)
                    return res;   
            }       
        }
        return -1;
     }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.