/**
* @author cookie
* @param {string} s
* @param {number} numRows
* @return {string}
*/
var convert = function(s, numRows) {
if(numRows<=1) return s;
const length = s.length;
const size = 2*numRows-2;
let res = "";
for(let j=0; j<=size/2; j++) {
for(let i=0; i<=parseInt(length/size); i++) {
let iCol1 = i*size + j;
let iCol2 = (i+1)*size + -j;
if(iCol1 < length) res += s[iCol1];
if(j==0 || j==size/2) continue;
if(iCol2 < length && iCol1!=iCol2) res += s[iCol2];
}
}
return res;
};
const result = convert('abcdefghijklmnopqrstuvwxyz',3)
console.log(result);
leetcode 6-z字形转换
最新推荐文章于 2021-11-19 12:59:39 发布