File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,8 @@ Step 2. Add the dependency
49
49
50
50
<summary >展开查看</summary >
51
51
52
+ https://leetcode.cn/problems/snail-traversal/
53
+
52
54
https://leetcode.cn/problems/function-composition
53
55
54
56
https://leetcode.cn/problems/array-reduce-transformation/
Original file line number Diff line number Diff line change
1
+ declare global {
2
+ interface Array < T > {
3
+ snail ( rowsCount : number , colsCount : number ) : number [ ] [ ] ;
4
+ }
5
+ }
6
+
7
+ Array . prototype . snail = function (
8
+ rowsCount : number ,
9
+ colsCount : number ,
10
+ ) : number [ ] [ ] {
11
+ // deno-lint-ignore no-this-alias
12
+ const nums = this ;
13
+ if (
14
+ rowsCount * colsCount !== this . length
15
+ ) return [ ] ;
16
+ return Array . from (
17
+ { length : rowsCount } ,
18
+ ( _ , i ) =>
19
+ Array . from (
20
+ { length : colsCount } ,
21
+ ( _ , j ) =>
22
+ j & 1
23
+ ? nums [ rowsCount - 1 - i + rowsCount * j ]
24
+ : nums [ i + rowsCount * j ] ,
25
+ ) ,
26
+ ) ;
27
+ } ;
You can’t perform that action at this time.
0 commit comments