My C++ 8ms Solution


  • -2
    C
        class Solution {
    public:
        bool isPowerOfTwo(int n) {
            if (n%2 != 0 && n != 1) return false;
            else if(n < 2 && n != 1) return false;
            else if(n == 2) return true;
            else if(n == 1) return true;
            else
            return isPowerOfTwo(n/2);
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.