dimanche 24 octobre 2021

Why we return the size of the vector in the given fucntion?

This is a function that removes the duplicate values from a vector. What is the significance of returning the size of the vector here? how will it print out the vector with no duplicate values?


    int removeDuplicates(vector<int>& nums) {
         nums.resize(distance(nums.begin(), unique(nums.begin(), nums.end())));
        return nums.size();
        
    }

Aucun commentaire:

Enregistrer un commentaire