Power of Two

Solution Code
class Solution:
    def isPowerOfTwo(self, n: int) -> bool:
        if n <= 0:
            return False
        
        while n % 2 == 0:
            n //= 2
            
        return n == 1
Video GuideLeetcode Daily

Time Complexity

O(1)

Space Complexity

O(1)