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
반응형
'Agorithm > 백준 알고리즘' 카테고리의 다른 글
백준 알고리즘 2512번 예산(python) (0) | 2021.01.31 |
---|---|
백준 알고리즘 2805번 나무 자르기(python) (0) | 2021.01.31 |
백준 알고리즘 13305번 주유소(python) (0) | 2021.01.31 |
백준 알고리즘 4796번 캠핑(python) (0) | 2021.01.31 |
백준 알고리즘 1946번 신입 사원(python) (0) | 2021.01.31 |