Simple List Scan

Linear search is the most straightforward way to find an item: you check the list from beginning to end. Given a list sequence and a value target, return the index of the first element equal to target. If the value is not found, return -1.

Примеры

Ввод
[0, 5, 7, 10, 15], 0
Вывод
0
Ввод
[0, 5, 7, 10, 15], 15
Вывод
4
Ввод
[0, 5, 7, 10, 15], 5
Вывод
1

Нужно реализовать

def linear_search(sequence: list, target: int) -> int:

Теги

array
PostgreSQLv16

Ovdje će se prikazati rezultat izvršavanja koda

Visible tests
1
Input
[0,5,7,10,15], 0
Expected0
2
Input
[0,5,7,10,15], 15
Expected4
3
Input
[0,5,7,10,15], 5
Expected1
4
Input
[0,5,7,10,15], 6
Expected-1
5
Input
[0], 1000
Expected-1
6
Input
[0,5,7,10,15], 3
Expected-1
Focus radio
Paused · SomaFM · Fluid