C++ 4 lines use sum


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

Log in to reply
 

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