Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dc4fb83

Browse files
committed
Add 20220426 level2 예상 대진표 풀이 추가
1 parent 0347649 commit dc4fb83

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

‎level-2/예상-대진표.js‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,30 @@ function solution(n, a, b) {
1313
}
1414
return currentRound
1515
}
16+
17+
//정답 2 - le2sky
18+
function solution(n, a, b) {
19+
let arr = Array.from({ length: n }, () => 0)
20+
arr[b - 1] = "B"
21+
arr[a - 1] = "A"
22+
23+
const isDiff = () => {
24+
return (
25+
(arr.indexOf("A") + 1 > arr.length / 2 && arr.indexOf("B") + 1 <= arr.length / 2) ||
26+
(arr.indexOf("A") + 1 <= arr.length / 2 && arr.indexOf("B") + 1 > arr.length / 2)) ? true : false
27+
};
28+
const isLeft = () => {
29+
return (arr.indexOf("A") + 1 > arr.length / 2) ? false : true
30+
};
31+
32+
//대진표의 절반을 기준으로 양옆에 A와 B가 있을 경우 log2N을 구하면 라운드 수가 나옴
33+
while (!isDiff()) {
34+
if (isLeft()) {
35+
arr.splice(arr.length / 2)
36+
} else {
37+
arr.splice(0, arr.length / 2)
38+
}
39+
}
40+
return Math.log2(arr.length)
41+
}
42+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /