Created
May 13, 2023 10:12
-
-
Save rnemeth90/6bc7f445141cb169c870f3c97707801b to your computer and use it in GitHub Desktop.
Go Linear Search
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
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