File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * 78. Subsets
3
+ * https://leetcode.com/problems/subsets/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given an integer array nums of unique elements, return all possible subsets (the power set).
7
+ *
8
+ * The solution set must not contain duplicate subsets. Return the solution in any order.
9
+ */
10
+
11
+ /**
12
+ * @param {number[] } nums
13
+ * @return {number[][] }
14
+ */
15
+ var subsets = function ( nums ) {
16
+ const result = [ ] ;
17
+ dfs ( [ ] , 0 ) ;
18
+
19
+ function dfs ( subset , start ) {
20
+ result . push ( subset ) ;
21
+ for ( let index = start ; index < nums . length ; index ++ ) {
22
+ dfs ( [ ...subset , nums [ index ] ] , index + 1 ) ;
23
+ }
24
+ }
25
+
26
+ return result ;
27
+ } ;
Original file line number Diff line number Diff line change 59
59
73|[ Set Matrix Zeroes] ( ./0073-set-matrix-zeroes.js ) |Medium|
60
60
74|[ Search a 2D Matrix] ( ./0074-search-a-2d-matrix.js ) |Medium|
61
61
77|[ Combinations] ( ./0077-combinations.js ) |Medium|
62
+ 78|[ Subsets] ( ./0078-subsets.js ) |Medium|
62
63
83|[ Remove Duplicates from Sorted List] ( ./0083-remove-duplicates-from-sorted-list.js ) |Easy|
63
64
88|[ Merge Sorted Array] ( ./0088-merge-sorted-array.js ) |Easy|
64
65
94|[ Binary Tree Inorder Traversal] ( ./0094-binary-tree-inorder-traversal.js ) |Easy|
You can’t perform that action at this time.
0 commit comments