32 ms C++ 4 line solution

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

  • 0

    Same solution here. Took advantage of the rules.
    Not quite pertinent, but it works. : )

Log in to reply

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