To remove duplicates from a std::vector in C++, the most common and efficient approach involves using std::sort and std::unique from the header, followed by std::vector::erase. This method modifies the original vector and sorts its elements.
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
vector<int> removeDuplicates(vector<int> arr){
sort(arr.begin(), arr.end());
arr.erase(unique(arr.begin(), arr.end()), arr.end());
return arr;
}