检查n是否为2的次幂

class Solution {
public:
bool isPowerOfTwo(int n) {
return (n>0&&(n&(n-1))==0);
}
};

posted @ 2024-08-19 13:57  东岸  阅读(13)  评论(0)    收藏  举报