Posted on

Description

Submission

class Solution {
public:
    vector<int> findDuplicates(vector<int>& nums) {
        int n = nums.size();
        vector<int> count(n+1, 0);

        vector<int> rets;
        for(int x: nums) {
            count[x]++;
            if(count[x] == 2) rets.push_back(x);
        }

        return rets;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *