Skip to content

Commit ec9dc03

Browse files
committed
update 40 & refine 46
1 parent 621ad65 commit ec9dc03

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

‎src/combination-sum-ii/res.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ var combinationSum2 = function(candidates, target) {
1717
calCombs(candis.slice(1), [...resArr, ele], targ-ele);
1818
}
1919

20-
calCombs(candis.slice(1), [...resArr], targ);
20+
let sliceIndex = 0;
21+
while (sliceIndex < candis.length && candis[0] === candis[sliceIndex]) {
22+
sliceIndex++;
23+
}
24+
calCombs(candis.slice(sliceIndex), [...resArr], targ);
2125
}
2226

2327
calCombs(candidates, [], target);

‎src/permutations/res.js

+24
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,27 @@ let subpermute = function(base, nums) {
4545

4646
return res;
4747
};
48+
49+
50+
/**
51+
* @param {number[]} nums
52+
* @return {number[][]}
53+
*/
54+
var permute = function(nums) {
55+
const len = nums.length;
56+
if (!len) return [];
57+
const res = [];
58+
59+
const enmurate = (preArr, candidates) => {
60+
if (candidates.length === 1) return res.push([...preArr, ...candidates]);
61+
62+
for (let i = 0; i < candidates.length; i++) {
63+
const temp = candidates.slice();
64+
temp.splice(i, 1);
65+
enmurate([...preArr, candidates[i]], temp);
66+
}
67+
}
68+
69+
enmurate([], nums.slice());
70+
return res;
71+
};

0 commit comments

Comments
 (0)