|
|
|
@ -42,7 +42,7 @@ function backtrack(
|
|
|
|
|
/* 求解子集和 II */
|
|
|
|
|
function subsetSumII(nums: number[], target: number): number[][] {
|
|
|
|
|
const state = []; // 状态(子集)
|
|
|
|
|
nums.sort(); // 对 nums 进行排序
|
|
|
|
|
nums.sort((a, b) => a - b); // 对 nums 进行排序
|
|
|
|
|
const start = 0; // 遍历起始点
|
|
|
|
|
const res = []; // 结果列表(子集列表)
|
|
|
|
|
backtrack(state, target, nums, start, res);
|
|
|
|
@ -56,4 +56,4 @@ const res = subsetSumII(nums, target);
|
|
|
|
|
console.log(`输入数组 nums = ${JSON.stringify(nums)}, target = ${target}`);
|
|
|
|
|
console.log(`所有和等于 ${target} 的子集 res = ${JSON.stringify(res)}`);
|
|
|
|
|
|
|
|
|
|
export {};
|
|
|
|
|
export { };
|
|
|
|
|