#题解# 2的幂
2的幂
https://www.nowcoder.com/practice/4a04240fd2be4e1287aab4af067f6d8f?tpId=196&rp=1&ru=%2Fexam%2Foj&qru=%2Fexam%2Foj&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26pageSize%3D50%26search%3D%26tab%3D%25E7%25AE%2597%25E6%25B3%2595%25E7%25AF%2587%26topicId%3D196&difficulty=&judgeStatus=0&tags=591&title=&gioEnter=menu
巧妙地运用了位运算和幂的特性
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param n int整型
* @return bool布尔型
*/
bool poweroftwo(int n) {
int count = (n & n-1);
return n > 0 && count == 0;
}
};