-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathNon Repeating Numbers.cpp
More file actions
69 lines (52 loc) · 1.23 KB
/
Non Repeating Numbers.cpp
File metadata and controls
69 lines (52 loc) · 1.23 KB
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
60
61
62
63
64
65
66
67
68
69
// { Driver Code Starts
#include<bits/stdc++.h>
using namespace std;
// } Driver Code Ends
class Solution
{
public:
vector<int> singleNumber(vector<int> nums)
{
// Code here.
int x1=0,a,b;
vector<int> v;
for(int i=0;i<nums.size();i++)
x1=nums[i]^x1;
int rmsb=x1 & -x1;//right most set bit
int x=0,y=0;
for(int i=0;i<nums.size();i++)
{
if((rmsb&nums[i])==0)
{
x=x^nums[i];
}
else
{
y=y^nums[i];
}
}
if(y<x)
return {y,x};
else
return {x,y};
}
};
// { Driver Code Starts.
int main(){
int T;
cin >> T;
while(T--)
{
int n;
cin >> n;
vector<int> v(2 * n + 2);
for(int i = 0; i < 2 * n + 2; i++)
cin >> v[i];
Solution ob;
vector<int > ans = ob.singleNumber(v);
for(auto i: ans)
cout << i << " ";
cout << "\n";
}
return 0;
} // } Driver Code Ends