LeetCode #231: Power of Two
β’ 37 words β’ 1 min
β’ updated
LeetCode #231: Power of Two:
class Solution:
def isPowerOfTwo(self, n: int) -> bool:
if n <= 0:
return False
while n & 1 == 0:
n >>= 1 # n //= 2
return n == 1
Related Posts
LeetCode #326: Power of Three:
python class Solution: def isPowerOfThree(self, n: int) -> bool: if n <= 0: return False while n != 1: if n % 3 β¦
Dec 24, 2025
LeetCode #355: Design Twitter:
My original solution:
python from collections import defaultdict from itertools import chain class Twitter: def β¦
Apr 06, 2026
Previously, previously, previously, previously, previously.
Thiago Perrotta