forked from Nimesh-Srivastava/DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0260.cpp
More file actions
36 lines (27 loc) · 673 Bytes
/
0260.cpp
File metadata and controls
36 lines (27 loc) · 673 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
class Solution {
public:
vector<int> singleNumber(vector<int>& nums) {
int xr = 0;
for(auto& n : nums)
xr ^= n;
int val = 1;
while(1){
if((val & xr) == 0)
val = val << 1;
else
break;
}
int a = 0;
int b = 0;
for(auto& n : nums){
if((n & val) == 0)
a ^= n;
else
b ^= n;
}
vector<int> result;
result.push_back(b);
result.push_back(a);
return result;
}
};