이분 검색

이세진·2022년 4월 15일
0

코테준비

목록 보기
22/87

생성일: 2022년 1월 14일 오후 5:27

구현 코드

# 이분검색
import sys
#sys.stdin = open("input.txt", "rt")
n, m = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
s = 0
e = n - 1

while s <= e:
    mid = (s+e)//2
    if l[mid] == m:
        print(mid+1)
        break
    elif l[mid] > m:
        e = mid - 1
    else:
        s = mid + 1
profile
나중은 결코 오지 않는다.

0개의 댓글