Power of Two @LeetCode
PROBLEM :
Given an integer, write a function to determine if it is a power of two.
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------
class Solution {
public:
bool isPowerOfTwo(int n) {
if(n<1) return false ;
if(n&(n-1))
return false ;
return true ;
}
};
---------------------------------------------------------------------------------
Given an integer, write a function to determine if it is a power of two.
--------------------------------------------------------------------------------
SIMPLE c++ IMPLEMENTATION :
--------------------------------------------------------------------------------
class Solution {
public:
bool isPowerOfTwo(int n) {
if(n<1) return false ;
if(n&(n-1))
return false ;
return true ;
}
};
---------------------------------------------------------------------------------
Comments
Post a Comment