have unique vector after sorting vector 1

have unique vector after sorting vector

vectorv ;//ex- v = {7, 3, 8, 3, 2, 8, 8, 5}
sort(v.begin(), v.end()); // v = {2,3,3,5,7,8,8,8}
v.erase(unique(v.begin(), v.end()), v.end());//v= {2, 3, 5, 7, 8}

Here is what the above code is Doing:
1. sort the vector
2. remove the duplicates
3. erase the extra elements

Similar Posts