hwangJi-dev/swiftAlgorithm

[Algorithm] 수 찾기

Opened this issue · 0 comments

https://www.acmicpc.net/problem/1920

N = int(input())
nrr = list(map(int, input().split()))
M = int(input())
mrr = list(map(int, input().split()))
nrr.sort()

for i in mrr:
    left = 0
    right = N - 1
    isTarget = False

    while left <= right:
        mid = int((left + right) / 2)
        
        if nrr[mid] == i:
            isTarget = True
            break
        if nrr[mid] > i:
            right = mid - 1
        else:
            left = mid + 1
        
        mid = int(right / 2)
    
    if isTarget:
        print(1)
    else:
        print(0)