Search
 
SCRIPT & CODE EXAMPLE
 

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;
    }
};
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ little endian or big endian 
Cpp :: create a vector of size n in c++ 
Cpp :: how to declare a 2d vector stack 
Cpp :: c++ thread wait fro 1 sec 
Cpp :: set iterator 
Cpp :: how to format big numbers with commas in c++ 
Cpp :: remove comments c++ 
Cpp :: potato 
Cpp :: intersection between vector c++ 
Cpp :: read a whole line from the input 
Cpp :: vectors in c++ 
Cpp :: c++ insert hashmap 
Cpp :: tabeau pseudo dynamique sur c++ 
Cpp :: c++ memset 
Cpp :: c++ if else example 
Cpp :: compare function in c++ 
Cpp :: c++ linked list 
Cpp :: merge sort in descending order c++ 
Cpp :: build a prefix array cpp 
Cpp :: vector size c++ 
Cpp :: quicksort algorithm 
Cpp :: ue4 c++ switch enum 
Cpp :: lcm in c++ 
Cpp :: c++ string replace 
Cpp :: CPP print executable name 
Cpp :: c++ get microseconds since epoch 
Cpp :: qtextedit no line break 
Cpp :: switch cout print with a prameter c++ 
Cpp :: A Subtask Problem codechef solution in cpp 
Cpp :: tu hi hai aashiqui song lyrics 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =