Link: https://leetcode.com/problems/power-of-two/
Solution:
Topics: bitwise, Pseudo palindromic paths in a binary tree
Intuition
This is a bitwise problem using the &
operator, see Pseudo palindromic paths in a binary tree for a detailed explanation on it
Implementation
def is_power(n):
if n == 0:
return False
return n & (-n) == n
#time: o(1)
#memory: o(1)
Visual