Bamboo is coming

[210908] 백준 1920 수찾기 실버4 문제풀이 python 본문

PS

[210908] 백준 1920 수찾기 실버4 문제풀이 python

twenty 2022. 1. 12. 15:03

 

- 알고리즘 분류 : 이분탐색

 


 

 

#백준 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)
 

 

완전탐색보다 시간복잡도가 훨씬 단축된다고 한다. 배울게 많다..


 

 

 

 

Comments