Skip to content

Instantly share code, notes, and snippets.

@s4553711
Created January 15, 2018 13:58
Show Gist options
  • Save s4553711/e50a34cb97047cab43e2336fe4c412ff to your computer and use it in GitHub Desktop.
Save s4553711/e50a34cb97047cab43e2336fe4c412ff to your computer and use it in GitHub Desktop.
class Solution {
public:
vector<int> findDuplicates(vector<int>& nums) {
vector<int> res;
for(int i = 0; i < nums.size(); i++) {
nums[abs(nums[i]) - 1] = -nums[abs(nums[i]) - 1];
if (nums[abs(nums[i]) - 1] > 0) res.push_back(abs(nums[i]));
}
return res;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment