Skip to content

Commit cf4a493

Browse files
committed
perf: update js solution to lc problem: No.0006
No.0006.ZigZag Conversion
1 parent db9ba30 commit cf4a493

File tree

3 files changed

+9
-33
lines changed

3 files changed

+9
-33
lines changed

solution/0000-0099/0006.ZigZag Conversion/README.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,10 @@ var convert = function (s, numRows) {
239239
if (numRows == 1) return s;
240240
let arr = new Array(numRows);
241241
for (let i = 0; i < numRows; i++) arr[i] = [];
242-
let index = 0,
243-
len = s.length,
244-
mi = 0,
242+
let mi = 0,
245243
isDown = true;
246-
while (index < len) {
247-
arr[mi].push(s[index]);
248-
index++;
244+
for (const c of s) {
245+
arr[mi].push(c);
249246

250247
if (mi >= numRows - 1) isDown = false;
251248
else if (mi <= 0) isDown = true;
@@ -259,11 +256,6 @@ var convert = function (s, numRows) {
259256
}
260257
return ans.join('');
261258
};
262-
263-
const s = 'AB',
264-
numRows = 1;
265-
266-
console.log(convert(s, numRows));
267259
```
268260

269261
### **TypeScript**

solution/0000-0099/0006.ZigZag Conversion/README_EN.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,10 @@ var convert = function (s, numRows) {
233233
if (numRows == 1) return s;
234234
let arr = new Array(numRows);
235235
for (let i = 0; i < numRows; i++) arr[i] = [];
236-
let index = 0,
237-
len = s.length,
238-
mi = 0,
236+
let mi = 0,
239237
isDown = true;
240-
while (index < len) {
241-
arr[mi].push(s[index]);
242-
index++;
238+
for (const c of s) {
239+
arr[mi].push(c);
243240

244241
if (mi >= numRows - 1) isDown = false;
245242
else if (mi <= 0) isDown = true;
@@ -253,11 +250,6 @@ var convert = function (s, numRows) {
253250
}
254251
return ans.join('');
255252
};
256-
257-
const s = 'AB',
258-
numRows = 1;
259-
260-
console.log(convert(s, numRows));
261253
```
262254

263255
### **TypeScript**

solution/0000-0099/0006.ZigZag Conversion/Solution.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ var convert = function (s, numRows) {
77
if (numRows == 1) return s;
88
let arr = new Array(numRows);
99
for (let i = 0; i < numRows; i++) arr[i] = [];
10-
let index = 0,
11-
len = s.length,
12-
mi = 0,
10+
let mi = 0,
1311
isDown = true;
14-
while (index < len) {
15-
arr[mi].push(s[index]);
16-
index++;
12+
for (const c of s) {
13+
arr[mi].push(c);
1714

1815
if (mi >= numRows - 1) isDown = false;
1916
else if (mi <= 0) isDown = true;
@@ -27,8 +24,3 @@ var convert = function (s, numRows) {
2724
}
2825
return ans.join('');
2926
};
30-
31-
const s = 'AB',
32-
numRows = 1;
33-
34-
console.log(convert(s, numRows));

0 commit comments

Comments
 (0)