描述
Given an integer, write a function to determine if it is a power of two.
您在真实的面试中是否遇到过这个题?
无难度题目
class Solution {
public:
/**
* @param n: an integer
* @return: if n is a power of two
*/
bool isPowerOfTwo(int n) {
// Write your code here
while(n%2==0) n=n/2;
if(n==1) return true;
else return false;
}
};