Skip to content

Instantly share code, notes, and snippets.

@isteshkov
Last active June 21, 2022 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isteshkov/aa06890a10582cee4f3306a243f1c0f1 to your computer and use it in GitHub Desktop.
Save isteshkov/aa06890a10582cee4f3306a243f1c0f1 to your computer and use it in GitHub Desktop.
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