Skip to content

Commit 05a4192

Browse files
committed
[BOJ] 1920 수 찾기 (S4)
1 parent 905770b commit 05a4192

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

심수연/2주차/260107.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# https://www.acmicpc.net/problem/1920
2+
3+
import sys
4+
input = sys.stdin.readline
5+
6+
N = int(input())
7+
arr = list(map(int, input().split()))
8+
arr.sort()
9+
10+
M = int(input())
11+
nums = list(map(int, input().split()))
12+
13+
def binary_search(array, value):
14+
left = 0
15+
right = len(array) - 1
16+
17+
while left <= right:
18+
mid = (left + right) // 2
19+
if value == array[mid]:
20+
return 1
21+
elif value < array[mid]:
22+
right = mid - 1
23+
else:
24+
left = mid + 1
25+
return 0
26+
27+
for i in range(M):
28+
print(binary_search(arr, nums[i]))
29+
30+
31+

0 commit comments

Comments
 (0)