Skip to content

Commit 7a18fa8

Browse files
committed
69차 2번 제출
1 parent 411cb8c commit 7a18fa8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

live6/test69/문제2/이지은.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const input = parseInt(
2+
require('fs')
3+
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
4+
.toString()
5+
.trim(),
6+
10
7+
);
8+
9+
function solution(N) {
10+
let answer = [];
11+
let arr = [];
12+
for (let i = 1; i <= N; i++) {
13+
arr.push(i);
14+
}
15+
16+
function permute(tempArr, remainArr) {
17+
if (remainArr.length === 0) {
18+
answer.push(tempArr);
19+
return;
20+
}
21+
22+
for (let i = 0; i < remainArr.length; i++) {
23+
const current = remainArr[i];
24+
const remaining = remainArr.slice(0, i).concat(remainArr.slice(i + 1));
25+
26+
permute([...tempArr, current], remaining);
27+
}
28+
}
29+
30+
permute([], arr);
31+
32+
const result = answer.map((row) => row.join(' '));
33+
result.forEach((row) => console.log(row));
34+
}
35+
36+
solution(input);

0 commit comments

Comments
 (0)