0448.cpp (402B)
1 class Solution { 2 public: 3 vector<int> findDisappearedNumbers(vector<int> &nums) { 4 vector<int> res; 5 6 for (int i = 0; i < nums.size(); i++) { 7 int index = abs(nums[i]) - 1; 8 if (nums[index] > 0) nums[index] = -nums[index]; 9 } 10 11 for (int i = 0; i < nums.size(); i++) 12 if (nums[i] > 0) res.push_back(i + 1); 13 14 return res; 15 } 16 };