Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
463 B
4
Indexable
Never
int firstMissingPositive(vector<int>& nums) {
       set<int> s;
        for(int i = 0; i < nums.size(); i++){
            if(nums[i] > 0){
                s.insert(nums[i]);
            }   
        }
         vector<int> v{s.begin(), s.end()};
        set<int>::iterator it;
        int i = 1;
        for(it = s.begin(); it != s.end(); it++){
            if(*it != i)
                return i;
            i++;
        }
       return i; 
    }