My Code takes a long time,how to reduce?


  • 0
    P
    class Solution {
    public:
        vector<int> findDuplicates(vector<int>& nums) {
            vector<int>vec;
            unordered_map<int,int>um;
            for(auto i:nums)
            {
                um[i]++;
                if(um[i]>1)
                vec.push_back(i);
            }
            return vec;
        }
    };

Log in to reply
 

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