-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path448.cpp
More file actions
executable file
·24 lines (24 loc) · 754 Bytes
/
448.cpp
File metadata and controls
executable file
·24 lines (24 loc) · 754 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution {
public:
vector<int> findDisappearedNumbers(vector<int>& nums) {
vector<int> res;
int index = 0;
while (index < nums.size()){
if (index != nums[index] - 1 && nums[nums[index] - 1] == nums[index]){
//res.push_back(nums[index]);
// cout << 1 << endl;
}else if (index != nums[index] - 1){
int tmp = nums[nums[index] - 1];
nums[nums[index] - 1] = nums[index];
nums[index] = tmp;
index --;
}
index ++;
}
for (int i = 0; i < nums.size(); i++)
if (nums[i] - 1 != i){
res.push_back(i+1);
}
return res;
}
};