About zigzag A run time error for a example


  • 0
    F
    if(numRows==1) return s;
        int k=2*numRows;
        string temp=s;
        int len=s.length();
        int i=0;
        int j=0;
        int c=0;
        while(c<numRows){
             while(i<len){
                 temp[j]=s[i];
                 if(c==0||c==numRows-1) i=i+k-2;
                 else  i=i+k-2*c-2;
                 j=j+1;
                 if(i>len){
                     i=c+1;
                     break;
                 }
             }
             c++;
        }
        
       return temp;
    

    "Apalindromeisaword,phrase,number,orothersequenceofunitsthatcanbereadthesamewayineitherdirection,withgeneralallowancesforadjustmentstopunctuationandworddividers.",2

    my answer for the example is run time error,but my noppad++ is correct run. I don,t know the reason.


  • 0
    F

    I think your code is not correct. If (i == len), it won't come into the inner loop again.


Log in to reply
 

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