In this project, there are multiple sets
in which they hold values from 1 - 9. Within this, I need to efficiently determine if there are values that is unique in one set
but not others.
For Example:
std::set<int> s_1 = { 1, 2, 3, 4, 5 };
std::set<int> s_2 = { 2, 3, 4 };
std::set<int> s_3 = { 2, 3, 4, 6 };
Note: The number of sets
is unknown until runtime
.
As you can see, s_1
contains the unique value of 1
and 5
and s_3
contains the unique value of 6
.
After determining the unique values, the aforementioned sets
should then just contain the unique values like:
// s_1 { 1, 5 }
// s_2 { 2, 3, 4 }
// s_3 { 6 }
What I've tried so far is to loop
through all the sets
and record the count
of the numbers
that have appeared. However I wanted to know if there is a more efficient solution out there.