algorithm icon indicating copy to clipboard operation
algorithm copied to clipboard

6. Z 字形变换

Open JesseZhao1990 opened this issue 6 years ago • 0 comments

image image

/**
 * @param {string} s
 * @param {number} numRows
 * @return {string}
 */
var convert = function(s, numRows) {
    let result = new Array(numRows).fill("");
    let str = s.split("");
    let index =0
    while(index<str.length){
        for(let i=0;i<numRows && index< str.length;i++){
            result[i]+= str[index]
            index++;
        }
        for(let j=numRows-2;j>0 && index< str.length;j-- ){
            result[j]+=str[index]
            index++;
        }
    }
    return result.join("")
};

https://leetcode-cn.com/problems/zigzag-conversion/

JesseZhao1990 avatar Oct 12 '19 13:10 JesseZhao1990