Skip to content

Instantly share code, notes, and snippets.

@mym0404
Created June 6, 2022 14:41
Show Gist options
  • Save mym0404/aeb023bd361e8339dbe59af79085d9fb to your computer and use it in GitHub Desktop.
Save mym0404/aeb023bd361e8339dbe59af79085d9fb to your computer and use it in GitHub Desktop.
arr = [1, 2, 3, 3, 5, 6, 6, 8, 9, 10]
left, right = 0, 9
target = 8
answer = -1
while left <= right:
mid = (left + right) // 2
if arr[mid] >= target:
answer = mid
right = mid - 1
else:
left = mid + 1
print(answer) # 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment