class Solution { public: bool isPowerOfTwo(int n) { for(int i = 0; i <= 31; i++){ if(pow(2,i) == n){ return true; } } return false; } };
class Solution { public: bool isPowerOfTwo(int n) { return n > 0 && (n & (n-1)) == 0; } };
class Solution { public: bool isPowerOfTwo(int n) { return n > 0 && (n & (-n)) == n; } };