-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path448.txt
More file actions
30 lines (25 loc) · 658 Bytes
/
448.txt
File metadata and controls
30 lines (25 loc) · 658 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
25
26
27
28
29
30
class Solution {
public:
vector<int> findDisappearedNumbers(vector<int>& A) {
vector<int>res;
for(int i=0;i<A.size();i++){
A[i]--;
}
for(int i=0;i<A.size();i++){
if(A[i]==i)continue;
while(true){
if(A[i]==i||A[i]>=A.size())break;
int t=A[i];
if(A[t]==t)break;
A[i]=A[A[i]];
A[t]=t;
}
}
for(int i=0;i<A.size();i++){
if(A[i]!=i){
res.push_back(i+1);
}
}
return res;
}
};