C++ inplace solution in 3 lines


  • 0
    P
    vector<int> findDuplicates(vector<int>& nums) {
        vector<int> ans;
        for (auto i : nums) if ((nums[abs(i) - 1] *= -1) > 0) ans.push_back(abs(i));
        return ans;
    }

Log in to reply
 

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