My code in C++/C, 8 ms, 2 lines


  • 0
    J

    class Solution {
    public:
    bool isPowerOfTwo(int n) {
    if(n<=0) return 0;
    return (n&(n-1))==0;
    }
    };


Log in to reply
 

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