C++


  • 0
    Q
    class Solution {
    public:
        vector<int> findDuplicates(vector<int>& nums) {
            vector<int>res;
            int len = nums.size();
            for(int i = 0 ; i < len ; ++i){
                int x = abs(nums[i])%len;
                if(nums[x]>0){ nums[x] = -nums[x] ;}
                else res.push_back(abs(nums[i]));
            }
            return res;
        }
    };```

Log in to reply
 

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