Javascript solution


  • 0
    I
    var convert = function(s, numRows) {
        var gap = numRows*2-2;
        if(gap===0) return s;
        var result = '';
        for(var i=0; i<numRows; i++){
            for(var j=0;j<s.length/gap;j++){
                result = result.concat(s.charAt(j*gap+i));
                if(i>0 && i<numRows-1){
                    var offset = (numRows-i-1)*2;
                    result = result.concat(s.charAt(j*gap+i+offset));
                }
            }
        }
        return result;
    };

Log in to reply
 

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