Skip to content

Instantly share code, notes, and snippets.

@rnemeth90
Created May 13, 2023 10:12
Show Gist options
  • Save rnemeth90/6bc7f445141cb169c870f3c97707801b to your computer and use it in GitHub Desktop.
Save rnemeth90/6bc7f445141cb169c870f3c97707801b to your computer and use it in GitHub Desktop.
Go Linear Search
package main
import (
"fmt"
)
func main() {
fmt.Println("index:", linearSearch([]int{2, 10, 40, 30, 21, 41, 56}, 10))
}
func linearSearch(intSlice []int, value int) int {
for i, v := range intSlice {
if v == value {
return i
}
}
return -1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment