Skip to content

Commit e458b33

Browse files
committed
cpp
1 parent 26731ac commit e458b33

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public:
3+
vector<int> singleNumber(vector<int>& nums) {
4+
int firstxor=0;
5+
for(int i=0;i<nums.size();i++){
6+
firstxor=firstxor^nums[i];
7+
}
8+
firstxor=firstxor&(-firstxor);
9+
int a=0;
10+
int b=0;
11+
for(int i=0;i<nums.size();i++){
12+
if((nums[i]&firstxor)==0){
13+
a=a^nums[i];
14+
}
15+
else {
16+
b=b^nums[i];
17+
}
18+
}
19+
vector<int>V;
20+
V.push_back(a);
21+
V.push_back(b);
22+
return V;
23+
}
24+
};

0 commit comments

Comments
 (0)