Skip to content

Commit 1c005d9

Browse files
committed
Create 이분탐색.py
1 parent 5ce1d7a commit 1c005d9

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Python_BOJ_2023/이분탐색.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
n, m = map(int, input().split())
2+
arr = list(map(int, input().split()))
3+
4+
arr.sort()
5+
6+
lt, rt = 0, n - 1
7+
8+
while lt <= rt:
9+
mid = (lt + rt) // 2
10+
if arr[mid] == m:
11+
print(mid + 1)
12+
break
13+
14+
elif arr[mid] > m:
15+
rt = mid - 1
16+
elif arr[mid] < m:
17+
lt = mid + 1

0 commit comments

Comments
 (0)