Last active
June 21, 2022 20:51
-
-
Save isteshkov/aa06890a10582cee4f3306a243f1c0f1 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
func search(nums []int, target int) int { | |
low := 0 | |
high := len(nums)-1 | |
for low <= high { | |
mid := low + (high - low)/2 | |
guess := nums[mid] | |
if guess == target { | |
return mid | |
} | |
if guess > target { | |
high = mid - 1 | |
} else { | |
low = mid + 1 | |
} | |
} | |
return -1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment