algorithm
algorithm copied to clipboard
6. Z 字形变换

/**
* @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/