Bamboo is coming
[210908] 백준 1920 수찾기 실버4 문제풀이 python 본문
- 알고리즘 분류 : 이분탐색
#백준 1920 수찾기 실버4
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
M = int(input())
S = list(map(int,input().split()))
A.sort()
for i in S:
check = 0
start,end = 0,len(A)-1
while start <= end:
result = 0
mid = (start + end) //2
if A[mid] == i:
result = 1
break
elif A[mid] > i:
end = mid - 1
elif A[mid] < i:
start = mid +1
print(result)
완전탐색보다 시간복잡도가 훨씬 단축된다고 한다. 배울게 많다..
'PS' 카테고리의 다른 글
[210908] 백준 2751 수 정렬하기2 실버5 문제풀이 python (0) | 2022.01.12 |
---|---|
[210908] 백준 2750 수 정렬하기 브론즈1 문제풀이 python (0) | 2022.01.12 |
[210901] 프로그래머스 카펫 Lv.2 문제풀이 python (0) | 2022.01.12 |
[210820] 백준 20364번 부동산다툼 실버2 문제풀이 python (0) | 2022.01.12 |
[210820] 백준 9372번 상근이의 여행 실버4 문제풀이 python (0) | 2022.01.12 |
Comments