Условие
Показать переводThe list holds n distinct numbers taken from 0, 1, …, n, so exactly one number in that range is missing. Find it. (Hint: compare the expected total with the actual total.)
Implement missing_number(numbers).
Input
numbers: n distinct numbers from 0 to n.
Output
Return the missing number.
Ограничения
0 ≤ n ≤ 100,000
Примеры
Пример 1
Ввод:
numbers = [3, 0, 1]
Ожидаемый вывод:
expected = 2
Ввод:
std::vector<long long> numbers = {3, 0, 1};
Ожидаемый вывод:
long long expected = 2;
Ввод:
long[] numbers = new long[] {3, 0, 1};
Ожидаемый вывод:
long expected = 2;
Пояснение
n = 3, so the range is 0–3; 2 is missing.
Пример 2
Ввод:
numbers = [0]
Ожидаемый вывод:
expected = 1
Ввод:
std::vector<long long> numbers = {0};
Ожидаемый вывод:
long long expected = 1;
Ввод:
long[] numbers = new long[] {0};
Ожидаемый вывод:
long expected = 1;
Пояснение
n = 1 and the range is 0–1; 1 is missing.
Ссылки
Это задание адаптировано для CodeUtility. Следуйте условию и ограничениям выше.