Skip to content

Instantly share code, notes, and snippets.

@dariodip
Created March 20, 2021 13:35
Show Gist options
  • Save dariodip/442836b15243f6157c01383c0896740c to your computer and use it in GitHub Desktop.
Save dariodip/442836b15243f6157c01383c0896740c to your computer and use it in GitHub Desktop.
import math
func bsa(a []int, n int, t int) int {
lft := 0
rgt := n - 1
for lft <= rgt {
m := int(math.Floor(float64((lft + rgt) / 2)))
if a[m] < t {
lft = m + 1
} else if a[m] > t {
rgt = m - 1
} else {
return m
}
}
return -1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment