thiagowfx's avatar

Β¬ just serendipity πŸ€ (not just serendipity)

LeetCode #231: Power of Two

β€’ 37 words β€’ 1 min β€’ updated

LeetCode #231: Power of Two:

python
class Solution:
    def isPowerOfTwo(self, n: int) -> bool:
        if n <= 0:
            return False

        while n & 1 == 0:
            n >>= 1  # n //= 2

        return n == 1