Given an integer array nums of unique elements, return all possible subsets (the power set).
The solution set must not contain duplicate subsets. Return the solution in any order.
1 <= nums.length <= 10
-10 <= nums[i] <= 10
All the numbers of nums are unique.
/**
* @param {number[]} nums
* @return {number[][]}
*/
var subsets = function(nums) {
let result = [[]];
function backtracking(first, current) {
for(let i = first; i<nums.length; i++) {
current.push(nums[i]);
result.push([...current]);
backtracking(i+1, current);
current.pop();
}
}
backtracking(0, [])
return result;
};
핵심은 backtracking 할때 i+1 하여 전에 index와 중복되지 않게 하는 것!