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
Logga in för att se historik över inskick
Logga inLogga in för att använda AI-mentorn
Logga inVisible tests
1
Input
[0,5,7,10,15], 0Expected
02
Input
[0,5,7,10,15], 15Expected
43
Input
[0,5,7,10,15], 5Expected
14
Input
[0,5,7,10,15], 6Expected
-15
Input
[0], 1000Expected
-16
Input
[0,5,7,10,15], 3Expected
-1Focus radio
Paused · SomaFM · Fluid