[leetcode]231. Power of Two
Analysis
厉害的人总是那么的厉害呀~—— [菜鸡反省中~]
Given an integer, write a function to determine if it is a power of two.
判断一个数是否是2的指数。
Implement
class Solution {
public:
bool isPowerOfTwo(int n) {
if(n == 0)
return false;
while(n){
if(n == 1)
return true;
if(n%2 != 0)
return false;
n /= 2;
}
}
};