Skip to content

Commit eb4c0dc

Browse files
authored
Create TheDuplicateXorArrayProblem-I.cpp
1 parent 9d8846a commit eb4c0dc

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//Given: An array A with all elements occuring twice except for x that occur once.
2+
//To Do: Find the element x O(1) space and O(N) time
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
const int N = 1e6;
6+
int arr[N];
7+
8+
int main() {
9+
int n;
10+
cin >> n;
11+
12+
int all = 0;
13+
for(int i=0; i<n; i++){
14+
cin >> arr[i];
15+
all ^= arr[i];
16+
}
17+
18+
cout << all << endl;
19+
20+
return 0;
21+
}

0 commit comments

Comments
 (0)