Skip to content

Commit b8078c1

Browse files
committed
83차 1번 문제풀이
1 parent e9df834 commit b8078c1

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

live8/test83/문제1/황장현.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const input = require('fs')
2+
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3+
.toString()
4+
.trim()
5+
.split('\n')
6+
.map((el) => el.split(' ').map(Number));
7+
8+
function binarySearch(arr, target) {
9+
let start = 0;
10+
let end = arr.length - 1;
11+
12+
while (start <= end) {
13+
let mid = Math.floor((start + end) / 2);
14+
15+
if (arr[mid] === target) return 1;
16+
if (arr[mid] < target) start = mid + 1;
17+
else end = mid - 1;
18+
}
19+
20+
return 0;
21+
}
22+
23+
function solution(input) {
24+
const N = input[0][0];
25+
const cards = input[1];
26+
const M = input[2][0];
27+
const sangenCards = input[3];
28+
29+
cards.sort((a, b) => a - b);
30+
31+
const result = sangenCards.map((sangen) => binarySearch(cards, sangen));
32+
33+
return result.join(' ');
34+
}
35+
36+
console.log(solution(input));

0 commit comments

Comments
 (0)