Alle Herausforderungen
Einfach 0 gelöst 0% Erfolgsquote

First Negative Index

Find where the first negative number appears.

Problem

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.

Einschränkungen

0 ≤ length ≤ 100,000

Beispiele

Beispiel 1
Eingabe:
numbers = [4, 0, -2, -7]

Erwartete Ausgabe:
expected = 2
Eingabe:
std::vector<long long> numbers = {4, 0, -2, -7};

Erwartete Ausgabe:
long long expected = 2;
Eingabe:
long[] numbers = new long[] {4, 0, -2, -7};

Erwartete Ausgabe:
long expected = 2;

Erläuterung

-2 at index 2 is the first negative value.

Beispiel 2
Eingabe:
numbers = [1, 2, 3]

Erwartete Ausgabe:
expected = -1
Eingabe:
std::vector<long long> numbers = {1, 2, 3};

Erwartete Ausgabe:
long long expected = -1;
Eingabe:
long[] numbers = new long[] {1, 2, 3};

Erwartete Ausgabe:
long expected = -1;

Erläuterung

There are no negative numbers, so the answer is -1.

Referenzen

Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.

Von anderen lernen

Community-Lösungen

Noch keine veröffentlichten Lösungen. Löse die Aufgabe und teile als Erster eine Lösung.