Skip to content

Commit f8e3142

Browse files
authored
Create guess-the-number-using-bitwise-questions-i.cpp
1 parent 665b45c commit f8e3142

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Time: O(logn):
2+
// Space: O(1)
3+
4+
// bit manipulation
5+
class Solution {
6+
public:
7+
int findNumber() {
8+
int result = 0;
9+
for (int i = 0; i < 30; ++i) {
10+
if (commonSetBits(1 << i)) {
11+
result |= 1 << i;
12+
}
13+
}
14+
return result;
15+
}
16+
};

0 commit comments

Comments
 (0)