Skip to content

Commit

Permalink
#6 22.11.19 > 공주 구하기 다시풀기
Browse files Browse the repository at this point in the history
  • Loading branch information
beurmuz committed Nov 19, 2022
1 parent 1ab8e33 commit 24ec357
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/inf/stack,queue/6_rerere.js
Original file line number Diff line number Diff line change
@@ -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));
2 changes: 1 addition & 1 deletion src/inf/stack,queue/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 😥 |

0 comments on commit 24ec357

Please sign in to comment.