File tree Expand file tree Collapse file tree 3 files changed +54
-0
lines changed
solution/0000-0099/0078.Subsets Expand file tree Collapse file tree 3 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -315,4 +315,27 @@ function subsets(nums: number[]): number[][] {
315
315
316
316
<!-- solution: end -->
317
317
318
+ <!-- solution: start -->
319
+
320
+ ### 方法三
321
+
322
+ <!-- tabs: start -->
323
+
324
+ #### TypeScript
325
+
326
+ ``` ts
327
+ function subsets(nums : number []): number [][] {
328
+ const res: number [][] = [[]];
329
+ for (const x of nums ) {
330
+ res .push (... res .map (arr => [... arr , x ]));
331
+ }
332
+
333
+ return res ;
334
+ }
335
+ ```
336
+
337
+ <!-- tabs: end -->
338
+
339
+ <!-- solution: end -->
340
+
318
341
<!-- problem: end -->
Original file line number Diff line number Diff line change @@ -313,4 +313,27 @@ function subsets(nums: number[]): number[][] {
313
313
314
314
<!-- solution: end -->
315
315
316
+ <!-- solution: start -->
317
+
318
+ ### Solution 3
319
+
320
+ <!-- tabs: start -->
321
+
322
+ #### TypeScript
323
+
324
+ ``` ts
325
+ function subsets(nums : number []): number [][] {
326
+ const res: number [][] = [[]];
327
+ for (const x of nums ) {
328
+ res .push (... res .map (arr => [... arr , x ]));
329
+ }
330
+
331
+ return res ;
332
+ }
333
+ ```
334
+
335
+ <!-- tabs: end -->
336
+
337
+ <!-- solution: end -->
338
+
316
339
<!-- problem: end -->
Original file line number Diff line number Diff line change
1
+ function subsets ( nums : number [ ] ) : number [ ] [ ] {
2
+ const res : number [ ] [ ] = [ [ ] ] ;
3
+ for ( const x of nums ) {
4
+ res . push ( ...res . map ( arr => [ ...arr , x ] ) ) ;
5
+ }
6
+
7
+ return res ;
8
+ }
You can’t perform that action at this time.
0 commit comments