File tree Expand file tree Collapse file tree 3 files changed +9
-33
lines changed
solution/0000-0099/0006.ZigZag Conversion Expand file tree Collapse file tree 3 files changed +9
-33
lines changed Original file line number Diff line number Diff line change @@ -239,13 +239,10 @@ var convert = function (s, numRows) {
239
239
if (numRows == 1 ) return s;
240
240
let arr = new Array (numRows);
241
241
for (let i = 0 ; i < numRows; i++ ) arr[i] = [];
242
- let index = 0 ,
243
- len = s .length ,
244
- mi = 0 ,
242
+ let mi = 0 ,
245
243
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);
249
246
250
247
if (mi >= numRows - 1 ) isDown = false ;
251
248
else if (mi <= 0 ) isDown = true ;
@@ -259,11 +256,6 @@ var convert = function (s, numRows) {
259
256
}
260
257
return ans .join (' ' );
261
258
};
262
-
263
- const s = ' AB' ,
264
- numRows = 1 ;
265
-
266
- console .log (convert (s, numRows));
267
259
```
268
260
269
261
### ** TypeScript**
Original file line number Diff line number Diff line change @@ -233,13 +233,10 @@ var convert = function (s, numRows) {
233
233
if (numRows == 1 ) return s;
234
234
let arr = new Array (numRows);
235
235
for (let i = 0 ; i < numRows; i++ ) arr[i] = [];
236
- let index = 0 ,
237
- len = s .length ,
238
- mi = 0 ,
236
+ let mi = 0 ,
239
237
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);
243
240
244
241
if (mi >= numRows - 1 ) isDown = false ;
245
242
else if (mi <= 0 ) isDown = true ;
@@ -253,11 +250,6 @@ var convert = function (s, numRows) {
253
250
}
254
251
return ans .join (' ' );
255
252
};
256
-
257
- const s = ' AB' ,
258
- numRows = 1 ;
259
-
260
- console .log (convert (s, numRows));
261
253
```
262
254
263
255
### ** TypeScript**
Original file line number Diff line number Diff line change @@ -7,13 +7,10 @@ var convert = function (s, numRows) {
7
7
if ( numRows == 1 ) return s ;
8
8
let arr = new Array ( numRows ) ;
9
9
for ( let i = 0 ; i < numRows ; i ++ ) arr [ i ] = [ ] ;
10
- let index = 0 ,
11
- len = s . length ,
12
- mi = 0 ,
10
+ let mi = 0 ,
13
11
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 ) ;
17
14
18
15
if ( mi >= numRows - 1 ) isDown = false ;
19
16
else if ( mi <= 0 ) isDown = true ;
@@ -27,8 +24,3 @@ var convert = function (s, numRows) {
27
24
}
28
25
return ans . join ( '' ) ;
29
26
} ;
30
-
31
- const s = 'AB' ,
32
- numRows = 1 ;
33
-
34
- console . log ( convert ( s , numRows ) ) ;
You can’t perform that action at this time.
0 commit comments