Alternative bit trick solution c++ using n&(-n)


  • 0
    B
    class Solution {
    public:
        bool isPowerOfTwo(int n) {
            return n>0 && n==int(n&(-n));
        }
    };
    

Log in to reply
 

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