728x90
반응형
Solution
- Use Bitwise operator
class Solution {
public:
bool isPowerOfTwo(int n) {
if (n < 0)
{
return false;
}
else
{
return n && !(n & n - 1);
}
}
};
728x90
반응형
'코딩 문제' 카테고리의 다른 글
[LeetCode] 728. Self Dividing Numbers, C++ (0) | 2023.01.26 |
---|---|
[LeetCode] 2032. Two Out of Three, C++ (0) | 2023.01.25 |
[LeetCode] 2331. Evaluate Boolean Binary Tree, cpp (0) | 2023.01.10 |
[LeetCode] 1880. Check if Word Equals Summation of Two Words, C (0) | 2023.01.05 |
[LeetCode] 2406. Divide Intervals Into Minimum Number of Groups, C (0) | 2023.01.02 |