-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.js
More file actions
31 lines (28 loc) · 750 Bytes
/
solution.js
File metadata and controls
31 lines (28 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* @param {number} N
* @return {number}
*/
var countArrangement = function(N) {
let res = [],
candidates = []
for (let i = 1; i <= N; i++)
candidates.push(i)
backTrack(candidates, [], res)
return res.length
};
var backTrack = function (candidates, temp, res) {
if (candidates.length == 0) {
res.push(temp)
} else {
let i = temp.length + 1
candidates.forEach((c, index) => {
if (c % i == 0 || i % c == 0) {
let tempCandidates = candidates.slice(),
t = temp.slice()
tempCandidates.splice(index, 1)
t.push(c)
backTrack(tempCandidates, t, res)
}
})
}
};