Given an integer, write a function to determine if it is a power of two.
判断一个整数是不是2的次方:
class Solution {
public:
bool isPowerOfTwo(int n) {
int cnt = 0;
while (n > 0) {
cnt += (n & 1);
n >>= 1;
}
return cnt == 1;
}
};