You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function dfs (arr, index) {
if (arr.length <= nums.length) {
res.push(arr.slice());
}
for (let i = index; i < nums.length; i++) {
if (i === index || nums[i] !== nums[i - 1] ) { // 判断当前元素与上一个元素不同
arr.push(nums[i]);
dfs(arr, i + 1);
arr.pop();
}
}
}
2、给一个没有重复元素的数组,返回不重复的子集
function dfs (arr, index) {
if (arr.length <= nums.length) {
res.push(arr.slice());
}
for (let i = index; i < nums.length; i++) {
arr.push(nums[i]);
dfs(arr, i + 1); // 使用 i + 1
arr.pop();
}
}
The text was updated successfully, but these errors were encountered:
1、给一个升序的有重复元素的数组,返回不重复的子集
2、给一个没有重复元素的数组,返回不重复的子集
The text was updated successfully, but these errors were encountered: