The Power of Two solutions are below.
15 Jun 2024•Easy•C++ / Python / TypeScript
Power of Two
C++, Python and TypeScript solutions for Power of Two.
Solution files
Python•power-of-two/synced-solution.py
def isPowerOfTwo(n: int) -> bool:
return n > 0 and (n & (n - 1)) == 0
C++•power-of-two/synced-solution.cpp
class Solution {
public:
bool isPowerOfTwo(int n) {
return n > 0 && (n & (n - 1)) == 0;
}
};
TypeScript•power-of-two/synced-solution.ts
function isPowerOfTwo(n: number): boolean {
return n > 0 && (n & (n - 1)) === 0;
}