USING SIMPLE MATHS ..


  • 0
    N
     int missingNumber(vector<int>& nums) {
            
        int len=nums.size();
         int sum=0;
            for(int i =0 ; i< len ; i++)
            sum+=nums[i];
            
            int t = (len*(len+1))/2;
                   return t-sum;
        }
    

    We can use the property of sum of n natural numbers .. (n*(n+1))/2 ..


Log in to reply
 

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