auto-generated entry for Power of Two. the solution files are available below.
solution files
- C++
power-of-two/synced-solution.cpp - Python
power-of-two/synced-solution.py - TypeScript
power-of-two/synced-solution.ts
Collected C++, Python, TypeScript solutions for power of two. Add a dedicated write-up later if you want deeper notes.
auto-generated entry for Power of Two. the solution files are available below.
power-of-two/synced-solution.cpppower-of-two/synced-solution.pypower-of-two/synced-solution.tsdef isPowerOfTwo(n: int) -> bool:
return n > class="syntax-number">0 and (n & (n - class="syntax-number">1)) == class="syntax-number">0
class Solution {
public:
bool isPowerOfTwo(int n) {
return n > class="syntax-number">0 && (n & (n - class="syntax-number">1)) == class="syntax-number">0;
}
};
function isPowerOfTwo(n: number): boolean {
return n > class="syntax-number">0 && (n & (n - class="syntax-number">1)) === class="syntax-number">0;
}