[C++] a method using set
Intuition\n Describe your first thoughts on how to solve this problem. \nTake components in the following way:\n- take components included either of two vectors
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nTake components in the following way:\n- take components included either of two vectors first\n- then take ones appearing in the two vectors\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe problem can be interpretd as "By extracting at most n/2 elements from each vector, calculate the maximum number of kinds of components created using the exctracted components". It means only numbers are important and the amount of each numbers appearing in each vector does not play an important role.\n\nAs shown in my solution, numbers are separated into the two types:\n- one contained in either of the two vectors\n- one contained in the both\n\nThen the results could be obtained.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(nlogn), where n is the number of components.\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(nlogn) since sets are used.\n\n# Code\n```\nstruct Info {\n    int only;\n    int common;\n};\n\nclass Solution {\npublic:\n    std::set<int> get_set(const vector<int>& v) const {\n        std::set<int> s;\n        for(const int n : v){\n            s.insert(n);\n        }\n        return std::move(s);\n    }\n    Info get_info(const std::set<int>& target, const std::set<int>& compare) const {\n        int only = 0;\n        int common = 0;\n        for(const int n : target){\n            if(compare.count(n) > 0){\n                common++;\n            }else{\n                only++;\n            }\n        }\n        return std::move(\n            Info(only, common)\n        );\n    }\n    int maximumSetSize(vector<int>& nums1, vector<int>& nums2) {\n        int n = nums1.size();\n        int count = 0;\n        std::set<int> s1, s2;\n        s1 = get_set(nums1);\n        s2 = get_set(nums2);\n        Info i1 = get_info(s1, s2);\n        Info i2 = get_info(s2, s1);\n        int common = i1.common;\n        int only1 = std::min(i1.only, n/2);\n        int only2 = std::min(i2.only, n/2);\n        int common_n = std::min(std::max(n - only1 - only2, 0), common);\n        return only1 + only2 + common_n;\n    }\n};\n```
['C++']