Skip to content

Commit eebbff1

Browse files
authored
Added solution for single number iii (#379)
1 parent d17ee7f commit eebbff1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

C++/single-number-iii.cpp

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

0 commit comments

Comments
 (0)