Skip to content

Latest commit

 

History

History
27 lines (18 loc) · 342 Bytes

231.md

File metadata and controls

27 lines (18 loc) · 342 Bytes

Power of Two

Description

link


Solution

Power of 2 means there is only 1 in bit-form


Code

O(n)

class Solution:
    def isPowerOfTwo(self, n):
        """
        :type n: int
        :rtype: bool
        """
        return n > 0 and not (n & n-1)