Skip to content

Commit 85a3bfb

Browse files
78. Subsets
Solution using backtracking and js
1 parent 9b78973 commit 85a3bfb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

javascript/78. Subsets.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var subsets = function(nums) {
2+
let ans = new Array(), curr = [];
3+
ans.push([]);
4+
function backtracking(i){
5+
if(i >= nums.length)return;
6+
for(let j = i; j < nums.length; j++){
7+
curr.push(nums[j]);
8+
ans.push([...curr]);
9+
backtracking(j + 1);
10+
curr.pop();
11+
}
12+
}
13+
backtracking(0);
14+
return ans
15+
};

0 commit comments

Comments
 (0)