Created
November 15, 2020 10:20
-
-
Save ceth-x86/bd80a8e04f3ad66bb3dc9ca9aef8c057 to your computer and use it in GitHub Desktop.
This file contains 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 main() { | |
a := []int{1, 3, 6, 10, 15, 21, 28, 36, 45, 55} | |
x := 6 | |
i := sort.Search(len(a), func(i int) bool { return a[i] >= x }) | |
if i < len(a) && a[i] == x { | |
fmt.Printf("found %d at index %d in %v\n", x, i, a) | |
} else { | |
fmt.Printf("%d not found in %v\n", x, a) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment