First Matching Position
Finding an index is useful when you need to know not just whether an element exists, but where it is located. The function find_index receives a list of numbers nums and a number target. Return the index of the first occurrence of target, or -1 if it is not in the list.
Примеры
Ввод
([1, 2, 3], 2)Вывод
1Ввод
([1, 2, 3], 9)Вывод
-1Ввод
([], 1)Вывод
-1Нужно реализовать
def find_index(nums: list[int], target: int) -> int:
Теги
liststwo-pointers
Entre para ver seu histórico de envios
EntrarEntre para usar o AI Mentor
EntrarVisible tests
1
Input
[1,2,3], 2Expected
12
Input
[1,2,3], 9Expected
-13
Input
[], 1Expected
-14
Input
[5,5,5], 5Expected
05
Input
[4,3,2,1], 1Expected
36
Input
[1,2,3], 1000Expected
-1Focus radio
Paused · SomaFM · Fluid