Created
June 6, 2022 14:41
-
-
Save mym0404/aeb023bd361e8339dbe59af79085d9fb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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