Все задачи
Легко Решено: 0 Процент решений: 0%

First Negative Index

Find where the first negative number appears.

Условие

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.

Ограничения

0 ≤ length ≤ 100,000

Примеры

Пример 1
Ввод:
numbers = [4, 0, -2, -7]

Ожидаемый вывод:
expected = 2
Ввод:
std::vector<long long> numbers = {4, 0, -2, -7};

Ожидаемый вывод:
long long expected = 2;
Ввод:
long[] numbers = new long[] {4, 0, -2, -7};

Ожидаемый вывод:
long expected = 2;

Пояснение

-2 at index 2 is the first negative value.

Пример 2
Ввод:
numbers = [1, 2, 3]

Ожидаемый вывод:
expected = -1
Ввод:
std::vector<long long> numbers = {1, 2, 3};

Ожидаемый вывод:
long long expected = -1;
Ввод:
long[] numbers = new long[] {1, 2, 3};

Ожидаемый вывод:
long expected = -1;

Пояснение

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

Ссылки

Это задание адаптировано для CodeUtility. Следуйте условию и ограничениям выше.

Учитесь у других

Решения сообщества

Пока нет опубликованных решений. Решите задание, чтобы поделиться первым.