I'm only using std::vector
in this problem, and I can guarantee no duplicates in each vector (but there isn't any order in each vector). How do I union the vectors I have?
Example:
If I have following vectors...
1
1
3 2
5
5 4
2
4
4 2
After the union I should have only two vectors left:
1
2 3 4 5
Again I'm only using vector, std::set
isn't allowed.
You can use std::set_union algorithm.
Refer :http://www.cplusplus.com/reference/algorithm/set_union/
Here is my code:
Sort the vectors, then merge them like in mergesort, but don't insert duplicates.