Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

Find duplicates in an array geeks for geeks solution in cpp

class Solution{
  public:
    vector<int> duplicates(int arr[], int n) {
        // code here
        vector<int> v;
        
        sort(arr,arr+n);
        
        for(int i=0;i<n;i++)
        {
            if(arr[i]==arr[i+1])
            {
                v.push_back(arr[i]);
            }
        }
        
        v.erase(unique(v.begin(),v.end()),v.end());
       
        if(v.empty())
        {
            v.push_back(-1);
        }
        
        return v;
    }
};
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #Find #duplicates #array #geeks #geeks #solution #cpp
ADD COMMENT
Topic
Name
1+9 =