Mercurial
view grok_interview/binary_search.py @ 58:ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Sat, 20 Dec 2025 09:33:15 -0800 |
| parents | 68fa88ac73fe |
| children |
line wrap: on
line source
x = [1,2,3,4,5,9,20,25,33,99] # | | target = 18 left = 0 right = len(x) while left < right: mid = (left + right)//2 if x[mid] == target: break elif x[mid] < target: left = mid + 1 else: right = mid print(x[mid])