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

来源:互联网 发布:诺曼底公爵 知乎 编辑:程序博客网 时间:2024/05/17 11:07

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;    }};



0 0