Class Solution for missing number


  • 0
    K

    class Solution {
    public:
    int missingNumber(vector<int>& nums) {

        sort(nums.begin(), nums.end());
        
        for(int i = 0; i<nums.size(); i++)
        {
            if(nums[i] != i)
            return i;
        }
        return nums.size();
        
    }
    

    };


Log in to reply
 

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