![](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2Fbt96sx%2FbtrEUjt17Qp%2FZ2hRGIkgaqbbXc95MKKjt1%2Fimg.png)
[알고리즘] 재귀 함수를 이용한 순열, 조합
·
알고리즘/풀이 힌트
순열? 모든 경우의 수를 계산하는 알고리즘이다. ( 순서 고려 O ) [ 1, 3, 5 ] 가 주어졌다면 1 3 5 1 5 3 3 1 5 3 5 1 5 1 3 5 3 1 처럼 모든 경우의 수를 구하는 방법이다. function permutations(arr, n) { if (n === 1) return arr.map((v) => [v]); let result = []; arr.forEach((fixed, idx, arr) => { const rest = arr.filter((_, index) => index !== idx); const perms = permutations(rest, n - 1); const combine = perms.map((v) => [fixed, ...v]); result.push..