File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 45
45
| 71| [ 简化路径] ( https://leetcode.cn/problems/simplify-path/ ) | [ JavaScript] ( ./algorithms/simplify-path.js ) | Medium|
46
46
| 73| [ 矩阵置零] ( https://leetcode.cn/problems/set-matrix-zeroes/ ) | [ JavaScript] ( ./algorithms/set-matrix-zeroes.js ) | Medium|
47
47
| 77| [ 组合] ( https://leetcode.cn/problems/combinations/ ) | [ JavaScript] ( ./algorithms/combinations.js ) | Medium|
48
+ | 78| [ 子集] ( https://leetcode.cn/problems/subsets/ ) | [ JavaScript] ( ./algorithms/subsets.js ) | Medium|
48
49
| 82| [ 删除排序链表中的重复元素 II] ( https://leetcode.cn/problems/remove-duplicates-from-sorted-list-ii/ ) | [ JavaScript] ( ./algorithms/remove-duplicates-from-sorted-list-ii.js ) | Medium|
49
50
| 83| [ 删除排序链表中的重复元素] ( https://leetcode.cn/problems/remove-duplicates-from-sorted-list/ ) | [ JavaScript] ( ./algorithms/remove-duplicates-from-sorted-list.js ) | Easy|
50
51
| 88| [ 合并两个有序数组] ( https://leetcode.cn/problems/merge-sorted-array/ ) | [ JavaScript] ( ./algorithms/merge-sorted-array.js ) | Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 78. 子集
3
+ * @param {number[] } nums
4
+ * @return {number[][] }
5
+ */
6
+ var subsets = function ( nums ) {
7
+ const result = [ ] ;
8
+ const path = [ ] ;
9
+
10
+ const backtracking = ( nums , startIndex = 0 ) => {
11
+ result . push ( path . slice ( ) ) ;
12
+ for ( let i = startIndex ; i < nums . length ; i ++ ) {
13
+ path . push ( nums [ i ] ) ;
14
+ backtracking ( nums , i + 1 ) ;
15
+ path . pop ( ) ;
16
+ }
17
+ } ;
18
+ backtracking ( nums ) ;
19
+
20
+ return result ;
21
+ } ;
You can’t perform that action at this time.
0 commit comments