Solving through the sum of first n number equation


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

Log in to reply
 

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