코딩테스트/이코테 2021
[이코테2021] 정렬된 배열에서 특정 수의 개수 구하기 [이진탐색] - Python
PgmJUN
2022. 6. 28. 13:12


from bisect import bisect_left, bisect_right
def numCnt():
# 배열에 찾고자 하는 값이 없다면 None 리턴
if x not in array:
return None
left_index = bisect_left(array, x)
right_index = bisect_right(array, x)
return right_index-left_index
n, x = map(int, input().split())
array = list(map(int, input().split()))
result = numCnt()
if result == None:
print(-1)
else:
print(result)