DevYoon
[๋ฐฑ์ค] 1920. ์ ์ฐพ๊ธฐ (Python) ๋ณธ๋ฌธ
link ๐ https://www.acmicpc.net/problem/1920
โ๏ธ ์ด๋ถํ์ ๋ฌธ์
โ๏ธ ๋ถ๋ช while๋ฌธ์ด ๋๋์ผ ํ๋๋ฐ ์๊พธ ๋ต์ด ์ ๋์ค๊ณ ๋์๊ฐ์ ๋นํฉํ๋ค. ์ฐพ์์ ๊ฒฝ์ฐ answer๋ฅผ 1๋ก ๋ฐ๊ฟ์ฃผ๊ณ break๋ฅผ ์ ์จ์ค ๊ฒ ์์ธ์ด์๋ค๐
N = int(input())
N_num = list(map(int, input().split()))
M = int(input())
M_num = list(map(int, input().split()))
N_num.sort()
def binary_search(ground, target):
s = 0
e = len(ground) - 1
answer = 0
while s <= e:
mid = (s+e) // 2
if ground[mid] > target:
e = mid - 1
elif ground[mid] < target:
s = mid + 1
else:
answer = 1
break
return answer
for num in M_num:
print(binary_search(N_num, num))