/**
* @param {string} s
* @param {number} numRows
* @return {string}
*/
var convert = function(s, numRows) {
// 存储结果
const rows = [];
// 指针下一次是加一还是减一
let add = false;
// 指针位置
let pointer = 0;
for (let index = 0; index < s.length; index++) {
if (!rows[pointer]) {
rows[pointer] = "";
}
rows[pointer] += s[index] || "";
if (pointer === 0 || pointer === numRows - 1) {
// 指针反转
add = !add;
}
pointer += add ? 1 : -1;
}
return rows.join("");
};
标签:index,rows,字形,题解,numRows,add,let,pointer,LeetCode From: https://www.cnblogs.com/wangshaojiea/p/16771178.html本文由一文多发运营工具平台 EaseWriting 发布