simple java solution


  • 1
    S

    public boolean isPowerOfTwo(int n) {

        if(n == 0) return false;
        
        
    	while (n % 2 == 0) {
    		n = n / 2;
    	}
    
    	if (n == 1)
    		return true;
    	
    	return false;
    
    }

Log in to reply
 

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