您的位置:首页 > 编程语言 > C语言/C++

leetcodeOJ 231. Power of Two

2017-04-06 12:01 106 查看
Given an integer, write a function to determine if it is a power of two.

//思路:power of two 表示n的bit位上只有一位为1
class Solution {
public:
bool isPowerOfTwo(int n) {
if(n <= 0)
return false;
return !(n&(n-1));
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  C++ leetcodeOJ 位操作