Skip to content

Commit 0fa77df

Browse files
committed
feat: add question 78
1 parent 25b350e commit 0fa77df

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

78.子集.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* @lc app=leetcode.cn id=78 lang=javascript
3+
*
4+
* [78] 子集
5+
*/
6+
7+
// @lc code=start
8+
/**
9+
* @param {number[]} nums
10+
* @return {number[][]}
11+
*/
12+
var subsets = function(nums) {
13+
const result = [];
14+
const n = 2 ** nums.length;
15+
for (let i = 0; i < n; i++) {
16+
const t = [];
17+
const str = i.toString(2);
18+
for (let j = 0; j < nums.length; j++) {
19+
if (str[j] === '1') {
20+
t.push(nums[str.length - 1 - j]);
21+
}
22+
}
23+
result.push(t);
24+
}
25+
return result;
26+
};
27+
// @lc code=end

0 commit comments

Comments
 (0)