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.

19 lines
251 B

3 years ago
package main
3 years ago
import "fmt"
3 years ago
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
}