Power of Two


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

Credits:
Special thanks to ​​​@jianchao.li.fighter​​ for adding this problem and creating all test cases.

class Solution {
public:
//n=0 以及n为负数 返回错误
bool isPowerOfTwo(int n) {

return (n>0 && !(n&n-1));
}
};