Dodomeki
Sign in

55. The Missing Identifier

Easy

A team records numeric identifiers starting at 0. The record should contain every identifier from 0 to n, but one was not written down.

You are given nums, a list of n distinct identifiers from that range. Return the identifier that is missing.

Example 1
Input: nums = [3, 0, 1]
Output: 2
Explanation: The expected range is 0 through 3, and identifier 2 does not appear.
Example 2
Input: nums = [0, 1]
Output: 2
Explanation: The expected range is 0 through 2, and identifier 2 is missing.
Example 3
Input: nums = [1]
Output: 0
Explanation: The only expected identifier is 0.
Constraints
  • 0 <= nums.length <= 10^5
  • nums contains nums.length distinct numbers
  • Each number in nums is in the range [0, nums.length]
BitsMathArrays
Caso 1
nums =
[3,0,1]
Expected =
2
Caso 2
nums =
[0,1]
Expected =
2
Caso 3
nums =
[1]
Expected =
0

Run checks these 3 cases. Submit runs all 11, including hidden ones.