diff --git a/codes/javascript/chapter_backtracking/subset_sum_i.js b/codes/javascript/chapter_backtracking/subset_sum_i.js index d07c85a2c..add812184 100644 --- a/codes/javascript/chapter_backtracking/subset_sum_i.js +++ b/codes/javascript/chapter_backtracking/subset_sum_i.js @@ -31,7 +31,7 @@ function backtrack(state, target, choices, start, res) { /* 求解子集和 I */ function subsetSumI(nums, target) { const state = []; // 状态(子集) - nums.sort(); // 对 nums 进行排序 + nums.sort((a, b) => a - b); // 对 nums 进行排序 const start = 0; // 遍历起始点 const res = []; // 结果列表(子集列表) backtrack(state, target, nums, start, res); diff --git a/codes/javascript/chapter_backtracking/subset_sum_ii.js b/codes/javascript/chapter_backtracking/subset_sum_ii.js index 293b468e6..78fcce604 100644 --- a/codes/javascript/chapter_backtracking/subset_sum_ii.js +++ b/codes/javascript/chapter_backtracking/subset_sum_ii.js @@ -36,7 +36,7 @@ function backtrack(state, target, choices, start, res) { /* 求解子集和 II */ function subsetSumII(nums, target) { const state = []; // 状态(子集) - nums.sort(); // 对 nums 进行排序 + nums.sort((a, b) => a - b); // 对 nums 进行排序 const start = 0; // 遍历起始点 const res = []; // 结果列表(子集列表) backtrack(state, target, nums, start, res); diff --git a/codes/typescript/chapter_backtracking/subset_sum_i.ts b/codes/typescript/chapter_backtracking/subset_sum_i.ts index b9e2497dd..eafd0150b 100644 --- a/codes/typescript/chapter_backtracking/subset_sum_i.ts +++ b/codes/typescript/chapter_backtracking/subset_sum_i.ts @@ -37,7 +37,7 @@ function backtrack( /* 求解子集和 I */ function subsetSumI(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); @@ -51,4 +51,4 @@ const res = subsetSumI(nums, target); console.log(`输入数组 nums = ${JSON.stringify(nums)}, target = ${target}`); console.log(`所有和等于 ${target} 的子集 res = ${JSON.stringify(res)}`); -export {}; +export { }; diff --git a/codes/typescript/chapter_backtracking/subset_sum_ii.ts b/codes/typescript/chapter_backtracking/subset_sum_ii.ts index ae010e65c..0d3175fcf 100644 --- a/codes/typescript/chapter_backtracking/subset_sum_ii.ts +++ b/codes/typescript/chapter_backtracking/subset_sum_ii.ts @@ -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 { };