feat:[78] 子集

This commit is contained in:
Wen 2023-06-29 14:33:29 +08:00
parent 7e6d871c61
commit f7b3eb6d97
1 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,26 @@
/*
* @lc app=leetcode.cn id=78 lang=javascript
*
* [78] 子集
*/
// @lc code=start
/**
* @param {number[]} nums
* @return {number[][]}
*/
var subsets = function (nums) {
const ret = [];
dp(nums, 0, [], ret);
return ret;
};
const dp = function (nums, index, cur, ret) {
if (index === nums.length) {
ret.push(cur);
return;
}
dp(nums, index + 1, cur.slice(), ret);
dp(nums, index + 1, cur.slice().concat(nums[index]), ret);
};
// @lc code=end