My simple boolean (2s complement) solution


  • 0
    I
    public class Solution {
    public boolean isPowerOfTwo(int n) {
        if(n == 0 || n == (int) (Math.pow(-2, 31) - 1))
            return false;
        if((-n & Math.abs(-n)) == n)
            return true;
        else
            return false;
    }
    

    }


Log in to reply
 

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