-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleet444.cpp
46 lines (44 loc) · 942 Bytes
/
leet444.cpp
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
#include <string.h>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <functional>
#include <cmath>
#include <set>
#include <map>
#include <assert.h>
#include <stack>
#include <unordered_map>
using namespace std;
class Solution {
public:
vector<int> findDuplicates(vector<int>& nums) {
int N = nums.size();
vector<int> re;
set<int> temp;
for(int i=0;i<N;i++)
{
while(nums[i]!=nums[nums[i]-1])
swap(nums[i],nums[nums[i]-1]);
if(nums[i]!=i+1 && temp.find(nums[i])==temp.end())
{
temp.insert(nums[i]);
re.push_back(nums[i]);
}
}
return re;
}
};
int main()
{
vector<int>t = {4,3,2,7,8,2,3,1};
Solution sol;
sol.findDuplicates(t);
return 0;
}