Efficient C++ Solution

  • 0

    This code improves the best case solution. No need to loop through till the end except for the last missing number. Also, less no. of XOR operations are needed in this solution. However, sorting is used as numbers may not be sorted in the given vector.

    int missingNumber(vector<int>& nums) {
          int i=0;
              if((nums[i] ^ i) !=0)break;          
          return i;

Log in to reply

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