티스토리 뷰
https://www.acmicpc.net/problem/1920
import sys
N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
M = int(sys.stdin.readline())
B = list(map(int, sys.stdin.readline().split()))
A = sorted(A)
result = []
def binarySerach(A, x, low, high):
if low > high:
return 0
else:
mid = (low+high) // 2
if x == A[mid]:
return 1
elif x < A[mid]:
return (binarySerach(A, x, low, mid -1))
else:
return(binarySerach(A, x, mid+1, high))
for i in range(M):
print(binarySerach(A, B[i], 0, N-1))
'Algorithm > Baekjoon' 카테고리의 다른 글
[백준] 2750 : 수 정렬하기 - Python (0) | 2020.04.14 |
---|---|
[백준] 1436 : 영화감독 숌 - Python (0) | 2020.04.14 |
[백준] 7568 : 덩치 - Python (0) | 2020.04.08 |
[백준] 10250 : ACM 호텔 - Python (0) | 2020.04.07 |
[백준] 2839 : 설탕 배달 - Python (0) | 2020.04.07 |