Skip to content

Commit a60d8cc

Browse files
committed
Create 6.Z 字形变换.js
1 parent f65b466 commit a60d8cc

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

6.Z 字形变换.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @param {string} s
3+
* @param {number} numRows
4+
* @return {string}
5+
*/
6+
var convert = function(s, numRows) {
7+
const t = [];
8+
for (let i = 0; i < numRows; i++) {
9+
t[i] = [];
10+
}
11+
12+
for (let i = 0, j = 0, inc = (numRows > 1 ? 1 : 0); i < s.length; i++) {
13+
t[j].push(s[i]);
14+
j += inc;
15+
if (j === 0 || j === numRows - 1) {
16+
inc = -inc;
17+
}
18+
}
19+
20+
return t.map(arr => arr.join('')).join('');
21+
};

0 commit comments

Comments
 (0)