There are more then one way to convert a vector with duplicate elements to a vector with
unique elements .
but here is best way .
we will use unique function and erase function together to acheive this goal .
code is :
sort(result.begin() , result.end());
result.erase(unique(result.begin() , result.end()), result.end());
i.e
first sort the vector , then erase those elements which are duplicates consecutively .
references :
https://practice.geeksforgeeks.org/problems/subsets-1587115621/1
Comments
Post a Comment