Here is the complete solution:
function isPowerOfTwo(n)
return n > 0 and (n & (n - 1)) = 0
The check n>0 excludes zero and negative numbers. The expression n&(n−1)=0 ensures exactly one 1 bit. Time: O(1). Space: O(1). This is the kind of elegant bit trick that impresses interviewers.