I want to check if there are common elements between 2 vectors. Is there a quicker way than looping through each element for both vectors and checking if they are the same?
By common element I mean an element "a" that exists in both vectors.
I only want to check IF there are common elements not how many, so I was thinking maybe I could use that to make a quicker piece of code.
I was also thinking of adding all elements to a set and checking if the set's size is equal to the sum of the sizes of the two vectors. Would this work?
The two vectors consist of vectors of chars. For example
vector<vector<char>> vec1 = {{'a','b'}, {'c'}}; vector<vector<char>> vec2 = {{'a'},{'b'},{'c'}}; // Notice that, in this case, {'c'} would the the common element // because it exists in both vectors
std::vector<std::set<char> >instead of astd::vector<std::vector<char> >?