Open Genzhen opened 3 years ago
const permute = function(n, k) {
const res = []
const used = {}
const recursion = (path) => {
if (path.length === k) {
res.push(path)
return
}
for (let i = 1; i <= n; i++) {
if (used[i]) {
continue
}
used[i] = true
recursion([...path, i])
used[i] = false
}
}
recursion([])
return res
};
扫描下方二维码,收藏关注,及时获取答案以及详细解析,同时可解锁800+道前端面试题。