Leetcode: Power of Two

Given an integer, write a function to determine if it is a power of two.



Similar Problems:


Given an integer, write a function to determine if it is a power of two.

Github: code.dennyzhang.com

Credits To: leetcode.com

Leave me comments, if you have better ways to solve.


## Blog link: https://code.dennyzhang.com/power-of-two
class Solution(object):
    def isPowerOfTwo(self, n):
        """
        :type n: int
        :rtype: bool
        """
        if n <= 0:
            return False
        return n & (n-1) == 0
linkedin
github
slack

Share It, If You Like It.

Leave a Reply

Your email address will not be published.