Submission shows the right output and some complex characters like "intstopu?\x02"


  • 0
    Y
    char* convert(char* s, int numRows) {
    int len=0;
    int i,j=0;
    int k=0;
    int rev=0;
    len=strlen(s);
    if(numRows<=1||len<=numRows){
        return s;
    }
    char *ans=malloc((len)*sizeof(char));
    int *seq=malloc(len*sizeof(int));
    for(i=0;i<len;i++){
        seq[i]=j;
        if(j==numRows-1){
            rev=1;
        }
        if(j==0){
            rev=0;
        }
        if(rev){
            j--;
        }
        if(!rev){
            j++;
        }
    }
    
    for(j=0;j<numRows;j++){
        for(i=0;i<len;i++){
            if(seq[i]==j){
                ans[k]=s[i];
                k=k+1;
            }
        }
    }
    return ans;
    

    }


Log in to reply
 

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