Skip to content

Commit df4b192

Browse files
committed
Create single-number-ii.cpp
1 parent 1336497 commit df4b192

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

C++/single-number-ii.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int singleNumber(vector<int>& nums) {
7+
int one = 0, two = 0;
8+
9+
for (const auto& i : nums) {
10+
int new_one = (~i & one) | (i & ~one & ~two);
11+
int new_two = (~i & two) | (i & one);
12+
one = new_one, two = new_two;
13+
}
14+
15+
return one;
16+
}
17+
};

0 commit comments

Comments
 (0)