C++ easy solution


  • 0
    B

    class Solution
    {
    public:
    vector<int> findDuplicates(vector<int>& nums)
    {
    vector<int> rec;
    set<int> tmpSet;
    auto itr = nums.begin();
    while(itr != nums.end())
    {
    if(tmpSet.count(*itr) > 0)
    {
    rec.push_back(*itr);
    }
    else
    {
    tmpSet.insert(*itr);
    }
    ++itr;
    }
    return rec;
    }
    };


Log in to reply
 

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