Skip to content

Commit d6c0938

Browse files
committed
[Silver IV] Title: 수 찾기, Time: 304 ms, Memory: 42184 KB -BaekjoonHub
1 parent d8a42d4 commit d6c0938

2 files changed

Lines changed: 46 additions & 3 deletions

File tree

백준/Silver/1920. 수 찾기/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
### 성능 요약
66

7-
메모리: 47016 KB, 시간: 416 ms
7+
메모리: 42184 KB, 시간: 304 ms
88

99
### 분류
1010

11-
이분 탐색, 자료 구조, 정렬
11+
자료 구조, 정렬, 이분 탐색, 집합과 맵, 해시를 사용한 집합과 맵
1212

1313
### 제출 일자
1414

15-
2024년 4월 8일 22:39:10
15+
2026년 2월 23일 12:28:26
1616

1717
### 문제 설명
1818

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* /dev/stdin */
2+
let fs = require("fs");
3+
let input = fs
4+
.readFileSync("/dev/stdin")
5+
.toString()
6+
.split("\n")
7+
.map((x) => x.replaceAll("\r", ""));
8+
9+
const N = Number(input[0]);
10+
const A = input[1]
11+
.split(" ")
12+
.map(Number)
13+
.sort((a, b) => a - b);
14+
15+
const M = Number(input[2]);
16+
const arrM = input[3].split(" ").map(Number);
17+
18+
let answer = [];
19+
20+
for (const x of arrM) {
21+
answer.push(binarySearch(A, x));
22+
}
23+
24+
console.log(answer.join("\n"));
25+
26+
function binarySearch(arr, target) {
27+
let left = 0;
28+
let right = arr.length - 1;
29+
30+
while (left <= right) {
31+
const mid = Math.floor((left + right) / 2);
32+
33+
if (arr[mid] === target) {
34+
return 1;
35+
} else if (arr[mid] < target) {
36+
left = mid + 1;
37+
} else {
38+
right = mid - 1;
39+
}
40+
}
41+
42+
return 0;
43+
}

0 commit comments

Comments
 (0)