Skip to content

Commit 2869b26

Browse files
committed
Create Single_Number_II.cc
1 parent acf4f3c commit 2869b26

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Single_Number_II.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
int singleNumber(int A[], int n) {
4+
// Note: The Solution object is instantiated only once and is reused by each test case.
5+
int One = 0, Two = 0, Three = 0;
6+
for (int i = 0; i < n; i++) {
7+
Two |= (One & A[i]);
8+
One ^= A[i];
9+
Three = One & Two;
10+
One &= (~Three);
11+
Two &= (~Three);
12+
}
13+
return (One | Two);
14+
}
15+
};

0 commit comments

Comments
 (0)