Skip to content

Commit e6b7311

Browse files
author
임빛나
committed
알고리즘 풀이 업데이트 - 큐
1 parent 0a4cdb4 commit e6b7311

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

section6/6.공주구하기.html

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<html>
2+
<head>
3+
<meta charset="UTF-8" />
4+
<title>출력결과</title>
5+
</head>
6+
<body>
7+
<script>
8+
function solution(n, k) {
9+
let queue = Array.from({ length: n }, (v, i) => i + 1);
10+
11+
let cnt = 0;
12+
13+
while (queue.length > 1) {
14+
let num = queue.shift();
15+
cnt++;
16+
17+
if (cnt === k) cnt = 0;
18+
else queue.push(num);
19+
}
20+
21+
return queue.shift();
22+
}
23+
24+
console.log(solution(8, 3));
25+
</script>
26+
</body>
27+
</html>

0 commit comments

Comments
 (0)