Power of Two

Problem Id: 231 Difficulty: Easy


Intuition

Solution


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