forked from go/golangs_learn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
251 B
18 lines
251 B
package main
|
|
|
|
import "fmt"
|
|
|
|
func main() {
|
|
|
|
list := []int{1, 2, 3, 45, 13, 16, 7}
|
|
fmt.Println(ListQuery(list, 13))
|
|
}
|
|
|
|
func ListQuery(list []int, k int) int {
|
|
for i, j := 0, len(list); i < j; i++ {
|
|
if list[i] == k {
|
|
return i
|
|
}
|
|
}
|
|
return -1
|
|
}
|
|
|