comparison grok_interview/binary_search.py @ 60:d64a8c189a77

Merged
author June Park <me@mrjunejune.com>
date Sat, 20 Dec 2025 13:56:01 -0500
parents 68fa88ac73fe
children
comparison
equal deleted inserted replaced
50:983769fba767 60:d64a8c189a77
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])