Very easy solution using binary XOR operator.


  • 0
    S

    Hello, dear users! Below you can see a simple way of solving this problem using binary XOR operator.

    int missingNumber(vector<int>& nums) {
        		int x = 0;
        		for (int i = 0; i < nums.size() + 1; i++)
        			x ^= i;
        		for (int i = 0; i < nums.size(); i++)
        			x ^= nums[i];
        		return x;
    }

Log in to reply
 

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