Write a function numInCommon
that accepts as parameters two references to vectors of integers,
and returns a count of the number of unique integers that appear in both vectors.
Use one or more Set
s as auxiliary storage to help you solve this problem.
For example, if two vectors v1
and v2
had the following values:
v1 = {3, 7, 3, -1, 2, 3, 7, 2, 15, 15}
v2 = {-5, 15, 2, -1, 7, 15, 36}
Your function would return 4
because the elements -1, 2, 7, and 15 occur in both vectors.
If the two vectors do not have any elements in common, or if either vector is empty, return 0
.
Do not modify either vector that is passed in.