what about this c++ solution? man


  • 0
    S
    class Solution {
    public:
        vector<int> intersect(vector<int>& nums1, vector<int>& nums2)
        {
            vector<int> res;
            for(auto num : nums1)
            {
                auto pos = find(nums2.begin(),nums2.end(),num);
                if( pos!=nums2.end())
                {
                    res.push_back(num);
                    nums2.erase(pos);
                }     
            }
            return res;
        }
    };
    

    what about this?


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.