C++ using maths concept


  • 0
    Y
    class Solution {
    public:
        int missingNumber(vector<int>& nums) {
            int sum=0;
            for(int num:nums)
            {
                sum+=num;
            }
            int correctSum = (nums.size()+1)*(nums.size())/2;
            return correctSum-sum;
        }
    };

Log in to reply
 

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