From 24ec3579e41e5382e67d624662a9e269da3bc9a4 Mon Sep 17 00:00:00 2001 From: beurmuz Date: Sat, 19 Nov 2022 15:44:32 +0900 Subject: [PATCH] =?UTF-8?q?#6=2022.11.19=20>=20=EA=B3=B5=EC=A3=BC=20?= =?UTF-8?q?=EA=B5=AC=ED=95=98=EA=B8=B0=20=EB=8B=A4=EC=8B=9C=ED=92=80?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/inf/stack,queue/6_rerere.js | 21 +++++++++++++++++++++ src/inf/stack,queue/README.md | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/inf/stack,queue/6_rerere.js diff --git a/src/inf/stack,queue/6_rerere.js b/src/inf/stack,queue/6_rerere.js new file mode 100644 index 00000000..d9877fab --- /dev/null +++ b/src/inf/stack,queue/6_rerere.js @@ -0,0 +1,21 @@ +"use strict"; + +function solution(n, k) { + let answer = 0; + let queue = Array.from({ length: n }, (value, index) => ++index); + let count = 0; + + while (queue.length) { + for (let i = 1; i < k; i++) { + queue.push(queue.shift()); + } + if (queue.length === 1) { + answer = queue.shift(); + break; + } + queue.shift(); + console.log(`-------${++count} Term, ${[...queue]}`); + } + return answer; +} +console.log(solution(8, 3)); diff --git a/src/inf/stack,queue/README.md b/src/inf/stack,queue/README.md index 9f079747..228079e4 100644 --- a/src/inf/stack,queue/README.md +++ b/src/inf/stack,queue/README.md @@ -11,5 +11,5 @@ | 3 | X | | 22.11.18 | | 4 | X | | 22.11.04 | | 5 | X | 예정 | 22.11.18 | -| 6 | X | | 22.11.18 | +| 6 | X | | 22.11.19 | | 7 | X | | 22.11.04 😥 |