Skip to content

Instantly share code, notes, and snippets.

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