Temukan duplikat dalam solusi array geeks for geeks di 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;
    }
};
coder