簡単 0件解決済み 正答率0%

Missing Number

Find the one number missing from 0..n.

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用に調整されています。上記の説明と制約に従ってください。

他の人の解答から学ぶ

コミュニティの解答

まだ公開された解答がありません。この課題を解いて最初の解答を共有しましょう。