位运算
```
class Solution {
public boolean isPowerOfTwo(int n) {
int cnt = 0;
while (n>0) {
if ((n & 1) == 1) cnt++;
n >>= 1;
}
return cnt == 1;
}
}
2024-02-09 10:20:04
位运算
```
class Solution {
public boolean isPowerOfTwo(int n) {
int cnt = 0;
while (n>0) {
if ((n & 1) == 1) cnt++;
n >>= 1;
}
return cnt == 1;
}
}
下一篇:LeetCode 231.2的幂