simple c++ using math


  • 0
    Z

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


Log in to reply
 

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