Constant additional space, O(n), sum approach


  • 0
    K

    class Solution {
    public:
    int missingNumber(vector<int>& nums) {
    int sum=0;
    for(auto iter=nums.begin(); iter!=nums.end();++iter)
    {
    sum+=*iter;
    }
    return (nums.size()0.5(nums.size()+1))-sum;
    }
    };


Log in to reply
 

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