4-line O(1) in space and O(n) in time C solution


  • 5
    A
    int missingNumber(int* nums, int numsSize) {
        int n = 0;
        for (int i = 0; i < numsSize; i++) {
            n ^= i ^ nums[i];
        }
        return n ^ numsSize;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.