백준 1920 수 찾기

김민영·2023년 1월 1일
0

알고리즘

목록 보기
21/125

계획

  • 이진 탐색
import sys
input = sys.stdin.readline
A = int(input())
A_lst = list(map(int, input().split()))
A_lst.sort()

B = int(input())
B_lst = list(map(int, input().split()))

def binSearch(s, e, target):

    while s <= e:
        m = (s+e) // 2
        if A_lst[m] == target:
            return 1
        elif A_lst[m] > target:
            e = m-1
        elif A_lst[m] < target:
            s = m+1
    return 0
for i in B_lst:
    print(binSearch(0, A-1, i))
  • 다른 사람들 코드 중, set 사용해서 & 연산하는 경우가 있었음.
profile
노션에 1차 정리합니당 - https://cream-efraasia-f3c.notion.site/4fb02c0dc82e48358e67c61b7ce8ab36?v=

0개의 댓글