-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathone_duplicate_in_array.cpp
More file actions
59 lines (49 loc) · 990 Bytes
/
one_duplicate_in_array.cpp
File metadata and controls
59 lines (49 loc) · 990 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
using namespace std;
int find_Duplicate(int n, int arr[])
{
int ans=0;
for(int i=0;i<n;i++){
ans=ans^arr[i];
}
for(int i=0;i<n;i++){
ans=ans^i;
}
return ans;
}
int main()
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
cout<<find_Duplicate(n,arr);
return 0;
}
// #include <bits/stdc++.h>
// using namespace std;
// int find_Duplicate(int n, int arr[]) {
// unordered_map<int,int>m;
// for(int i=0;i<n;i++){
// m[arr[i]]++;
// }
// for(auto x:m){
// if(x.second>1){
// return x.first;
// }
// }
// return 0;
// }
// int main()
// {
// int n;
// cin>>n;
// int arr[n];
// for(int i=0;i<n;i++){
// cin>>arr[i];
// }
// cout<<find_Duplicate(n,arr);
// return 0;
// }