백준 [ALGORITHM] - 수 찾기 (1920)
2024. 6. 13. 19:00ㆍ코딩/백준 [ALGORITHM]
반응형
def bin_search(array, target, start, end):
while start <= end:
mid = (start + end) // 2
if array[mid] == target:
return True
elif array[mid] > target:
end = mid - 1
else:
start = mid + 1
return False
n = int(input())
arr = list(map(int, input().split()))
m = int(input())
targets = list(map(int, input().split()))
sorted_arr = sorted(arr)
for target in targets:
if bin_search(sorted_arr, target, 0, len(sorted_arr) - 1):
print(1)
else:
print(0)
반응형
'코딩 > 백준 [ALGORITHM]' 카테고리의 다른 글
백준 [ALGORITHM] - 블랙잭 (2798) (0) | 2024.07.04 |
---|---|
백준 [ALGORITHM] - 세로 읽기 (10798) (0) | 2024.07.02 |
백준 [ALGORITHM] - 너의 평점은 (25206) (1) | 2024.06.04 |
백준 [ALGORITHM] - 그룹 단어 체커 (1316) (0) | 2024.06.02 |
백준 [ALGORITHM] - 최댓값 (2566) (0) | 2024.05.23 |