Skip to content

Create 78. Subsets.js #879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions solution/0000-0099/0078.Subsets/78. Subsets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

//* @param {number[]} nums
//* @return {number[][]}

Comment on lines +1 to +4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the initial state.

Suggested change
//* @param {number[]} nums
//* @return {number[][]}
/**
* @param {number[]} nums
* @return {number[][]}
*/

var subsets = function(nums) {
let result=[]

const dfs=(i,nums,slate)=>{

if(i===nums.length){
result.push(slate.slice())
return
}

dfs(i+1,nums,slate)
slate.push(nums[i])
dfs(i+1,nums,slate)
slate.pop()
}
dfs(0,nums,[])
return result
};
Comment on lines +5 to +22
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the code, we have certain formatting requirements. Prettier configuration files have been added to the project and can be formatted using an IDE.

Suggested change
var subsets = function(nums) {
let result=[]
const dfs=(i,nums,slate)=>{
if(i===nums.length){
result.push(slate.slice())
return
}
dfs(i+1,nums,slate)
slate.push(nums[i])
dfs(i+1,nums,slate)
slate.pop()
}
dfs(0,nums,[])
return result
};
var subsets = function (nums) {
let result = [];
const dfs = (i, nums, slate) => {
if (i === nums.length) {
result.push(slate.slice());
return;
}
dfs(i + 1, nums, slate);
slate.push(nums[i]);
dfs(i + 1, nums, slate);
slate.pop();
};
dfs(0, nums, []);
return result;
};