처음에 짠 코드
n, m = list(map(int, input().split()))
arr = list(map(int, input().split()))
start = arr[0]
end = arr[-1]
count = 0
while start <= end:
mid = (start + end) // 2
if arr[mid] == m:
count = arr.count(m)
elif arr[mid] > m:
end = mid - 1
else:
start = mid + 1
print(count)
BS를 적용한 코드
from bisect import bisect_left, bisect_right
def count_by_range(array, left_value, right_value):
right_index = bisect_right(array, right_value)
left_index = bisect_left(array, left_value)
return right_index - left_index
n, x = map(int, input().split())
array = list(map(int, input().split()))
count = count_by_range(array, x, x)
if count == 0:
print(-1)
else:
print(count)