-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom.cpp
More file actions
44 lines (33 loc) · 693 Bytes
/
random.cpp
File metadata and controls
44 lines (33 loc) · 693 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
#include<iostream>
using namespace std;
// int unique(int arrp, int n);
int setBit(int n, int pos){
return (n & (1<<pos)!=0);
}
void unique(int arr[], int n){
int position =0;
int xorsum=0;
for(int i=0;i<n;i++){
xorsum = xorsum^arr[i];
}
int tempxor=xorsum;
int setbit=0;
while(setbit!=1){
setbit = xorsum & 1;
position++;
xorsum = xorsum>>1;
}
int newxor=0;
for(int i=0; i<n;i++){
if(setBit(arr[i],position-1)){
newxor =newxor^arr[i];
}
}
cout<<newxor;
cout<<(tempxor^newxor);
}
int main(){
int arr[]= {1,2,3,4,3,2,1,5};
unique(arr,8);
return 0;
}