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

Leetcode 231. Power of Two (Easy) (cpp)

2016-07-13 18:16 597 查看
Leetcode 231. Power of Two (Easy) (cpp)

Tag: Math, Bit Manipulation

Difficulty: Easy

/*

231. Power of Two (Easy)

Given an integer, write a function to determine if it is a power of two.

*/
class Solution {
public:
bool isPowerOfTwo(int n) {
return n > 0 && ((n & (n - 1)) == 0 );
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: