Javascript solution is correct in browser,but error in OJ


  • -1
    S

    var reorderList = function(head) {

    if(head===null){
        return;
    }else{
        this.n=head.length;
        this.recorder = [];
        if(n===1){
            recorder.push(head[0]);
        }else if(n>0){
            recorder.push(head[0]);
             for(i=1;i<n;i++){
                if(i%2===1){
                    recorder.push(head[n-(i+1)/2]);
                }else if(i%2===0){
                    recorder.push(head[i/2]);
                }   
             }
         }
        for(j=0;j<n;j++){
            head[j]=recorder[j];
        }
        return;
    } 
    

    };

    The error is:

    Input:[1,2,3]

    Output:[1,2,3]

    Expected:[1,3,2]


    This solution run correct in browser ( [1,3,2] ),but is not accepted by OJ.
    Anyone know reason?


Log in to reply
 

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