Missing Number

Easy Subject: Bit Manipulation
Time Complexity
O(N)
Space Complexity
O(1)

Problem Description

Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array.

Optimal Solution

Python
def missingNumber(nums):
    n = len(nums)
    xor = 0
    for i in range(n + 1):
        xor ^= i
    for num in nums:
        xor ^= num
    return xor