Easy understand C++ solution


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

Log in to reply
 

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