728x90
반응형

아주 기본적인 이분 탐색 문제이다!

def binarySearch(li, n):
    s, e = 0, len(li)-1
    while s <= e:
        m = (s + e) // 2
        if li[m] == n:
            return 1
        elif li[m] <= n:
            s = m + 1
        else:
            e = m - 1
    return 0


_ = int(input())
li = sorted(list(map(int, input().split())))
N = int(input())
for n in list(map(int, input().split())):
    print(binarySearch(li, n))
728x90
반응형

+ Recent posts