how to improve? C++


  • 0
    Y
    class Solution {
    public:
        vector<int> findDuplicates(vector<int> nums) {
            vector<vector<int>> dup(nums.size()+1, vector<int>(0));
            vector<int> res={};
            for (int i:nums){
                dup[i].push_back(i);
            }
            for (auto j:dup){
                if (j.size()==2) res.push_back(j[0]);
            }
            return res;
        }
    };
    

Log in to reply
 

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