annotate grok_interview/binary_search.py @ 67:6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
| author |
June Park <parkjune1995@gmail.com> |
| date |
Wed, 24 Dec 2025 09:15:55 -0800 |
| parents |
68fa88ac73fe |
| children |
|
| rev |
line source |
|
51
|
1
|
|
|
2 x = [1,2,3,4,5,9,20,25,33,99]
|
|
|
3 # | |
|
|
|
4
|
|
|
5 target = 18
|
|
|
6 left = 0
|
|
|
7 right = len(x)
|
|
|
8
|
|
|
9 while left < right:
|
|
|
10 mid = (left + right)//2
|
|
|
11 if x[mid] == target:
|
|
|
12 break
|
|
|
13 elif x[mid] < target:
|
|
|
14 left = mid + 1
|
|
|
15 else:
|
|
|
16 right = mid
|
|
|
17
|
|
|
18 print(x[mid])
|