Please tell me why my solution is Runtime error,I am a freshman.


  • 0
    K

    char* longestCommonPrefix(char** strs, int strsSize) {
    char *result;
    int i,j;

    result=(char*)malloc(sizeof(char)*(strlen(strs[0])+1));
    strcpy(result,strs[0]);
    for(i=1;i<strsSize;++i){
        for(j=0;(result[j]==strs[i][j])&&(result[j]);++j){
            ;
        }
        result[j]='\0';
    }
    
    return result;
    

    }


Log in to reply
 

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