Skip to content

Commit

Permalink
Fix JS and TS sort bugs (krahets#784)
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-tse authored Sep 23, 2023
1 parent 1067f30 commit 2f727d8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion codes/javascript/chapter_backtracking/subset_sum_i.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion codes/javascript/chapter_backtracking/subset_sum_ii.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions codes/typescript/chapter_backtracking/subset_sum_i.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 { };
4 changes: 2 additions & 2 deletions codes/typescript/chapter_backtracking/subset_sum_ii.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 { };

0 comments on commit 2f727d8

Please sign in to comment.