We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 605f19d + c3a9a5f commit bde04a6Copy full SHA for bde04a6
June-LeetCoding-Challenge/08-Power-Of-Two/Power-Of-Two.cpp
@@ -5,4 +5,25 @@ class Solution {
5
if (x == 0) return false;
6
return (x & (-x)) == x;
7
}
8
-};
+};
9
+
10
+class Solution {
11
+public:
12
+ int right_most_setbit(int num) {
13
+ int pos = 0;
14
+ // counting the position of first set bit
15
+ for (int i = 0; i < 32; i++) {
16
+ if (!(num & (1 << i)))
17
+ pos++;
18
+ else
19
+ break;
20
+ }
21
+ return pos;
22
23
24
+ bool isPowerOfTwo(int n) {
25
+ if(n<=0) return false;
26
+ else return right_most_setbit(n) == int(log2(n));
27
28
29
0 commit comments