My C 8ms solution


  • 0
    T
    char* convert(char* s, int numRows) {
        if(numRows==1)
            return s;
        char* temp=s;
        int sSize=0;
        int period=2*(numRows-1);
        while(*(temp++))
            sSize++;
        int nCol=(sSize-1)/period+1;
        char * result=(char*)calloc(sSize+1,sizeof(char));
       
        int i=0;
        int j=0;
        int k=0;
        for(;i<numRows;i++){
            for(j=0;j<nCol;j++){
                if(i+period*j<sSize){
                    result[k++]=s[i+period*j];
                    if((period*(j+1)-i)%period&&((period*(j+1)-i)!=period/2+period*j)&&(period*(j+1)-i<sSize))
                        result[k++]=s[period*(j+1)-i];
               
                }
                
            }
        }
        
        return result;
            
    }

Log in to reply
 

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