90. Subsets II
Python
Javascript
var subsetsWithDup = function(nums) {
const result = [[]];
nums.sort();
const backtrack = function(counter, max, record = []) {
if (max === record.length) {
result.push(record.slice());
return;
}
for (let i = counter; i < nums.length; i++) {
const num = nums[i];
if (counter < i && nums[i] === nums[i - 1]) continue;
record.push(num);
backtrack(i + 1, max, record);
record.pop();
}
}
for (let i = 1; i <= nums.length; i++) {
backtrack(0, i)
}
return result;
};