LeetCode : Power of Two
Given an integer, write a function to determine if it is a power of two.
class Solution {
public:
bool isPowerOfTwo(int n) {
if(n<1)
return false;
if(n==1)
return true;
else
if(n%2==0)
return isPowerOfTwo(n/2);
else
return false;
}
};