Skip to content

Commit 8799493

Browse files
authored
Merge pull request #140 from Neil94n/neil
update Solution
2 parents 8be63be + 217cdb4 commit 8799493

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @param {string} s
3+
* @param {number} numRows
4+
* @return {string}
5+
*/
6+
var convert = function (s, numRows) {
7+
if (numRows == 1) return s
8+
let arr = new Array(numRows)
9+
for (let i = 0; i < numRows; i++) arr[i] = []
10+
let index = 0, len = s.length, mi = 0, isDown = true
11+
while (index < len) {
12+
arr[mi].push(s[index])
13+
index++
14+
15+
if (mi >= numRows - 1)
16+
isDown = false
17+
else if (mi <= 0)
18+
isDown = true
19+
20+
if (isDown) mi++
21+
else mi--
22+
}
23+
let ans = []
24+
for (let item of arr) {
25+
ans = ans.concat(item)
26+
}
27+
return ans.join("")
28+
};
29+
30+
const s = "AB", numRows = 1
31+
32+
console.log(convert(s, numRows))

0 commit comments

Comments
 (0)