Skip to content

Commit 841ef66

Browse files
committed
Create 3094-GuessTheNumberUsingBitwiseQuestionsII.cpp
1 parent ee7d876 commit 841ef66

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Definition of commonBits API.
3+
* int commonBits(int num);
4+
*/
5+
6+
class Solution {
7+
public:
8+
int findNumber() {
9+
int res(0), d(commonBits(0));
10+
for (int p = 0; p < 30; p++) {
11+
int mult = (1 << p);
12+
commonBits(mult);
13+
if(d == commonBits(0) - 1){res ^= mult;}
14+
commonBits(mult);
15+
}
16+
return res;
17+
}
18+
};

0 commit comments

Comments
 (0)