Problème
Find the position (counting from 0) of the first negative number in the list.
Implement first_negative_index(numbers).
Input
numbers: The list of integers.
Output
Return the index, or -1 if there are no negative numbers.
Contraintes
0 ≤ length ≤ 100,000
Exemples
Exemple 1
Entrée :
numbers = [4, 0, -2, -7]
Sortie attendue :
expected = 2
Entrée :
std::vector<long long> numbers = {4, 0, -2, -7};
Sortie attendue :
long long expected = 2;
Entrée :
long[] numbers = new long[] {4, 0, -2, -7};
Sortie attendue :
long expected = 2;
Explication
-2 at index 2 is the first negative value.
Exemple 2
Entrée :
numbers = [1, 2, 3]
Sortie attendue :
expected = -1
Entrée :
std::vector<long long> numbers = {1, 2, 3};
Sortie attendue :
long long expected = -1;
Entrée :
long[] numbers = new long[] {1, 2, 3};
Sortie attendue :
long expected = -1;
Explication
There are no negative numbers, so the answer is -1.
Références
Ce défi a été adapté pour CodeUtility. Suivez l'énoncé et les contraintes ci-dessus.