MCPcopy Index your code
hub / github.com/neetcode-gh/leetcode / dfs

Function dfs

javascript/0046-permutations.js:11–22  ·  view source on GitHub ↗
(nums, permutation = [], permutations = [])

Source from the content-addressed store, hash-verified

9};
10
11var dfs = function (nums, permutation = [], permutations = []) {
12 const isBaseCase = nums.length === permutation.length;
13 if (isBaseCase) return permutations.push(permutation.slice());
14
15 for (let i = 0; i < nums.length; i++) {
16 if (permutation.includes(nums[i])) continue;
17
18 backTrack(nums, i, permutation, permutations);
19 }
20
21 return permutations;
22};
23
24const backTrack = (nums, i, permutation, permutations) => {
25 permutation.push(nums[i]);

Callers 2

permuteFunction · 0.70
backTrackFunction · 0.70

Calls 2

backTrackFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected