0
点赞
收藏
分享

微信扫一扫

【leetcode】231-power-of-two

孟佳 2022-07-13 阅读 62
编程语言

problem

​​231-power-of-two​​

 solution1

class Solution {
public:
bool isPowerOfTwo(int n) {
if(n==0) return false;
while(n%2==0)
{
n /= 2;
}
return n==1;
}
};

View Code

solution2

【leetcode】231-power-of-two_其它

【leetcode】231-power-of-two_其它_02

class Solution {
public:
bool isPowerOfTwo(int n) {
if(n<=0) return false;
return !(n&(n-1));
}
};

View Code

 

 

 

参考

1. ​​Leetcode_231-power-of-two​​;

举报

相关推荐

0 条评论