코딩 문제
[Leet Code] 231. Power of Two, C++
Zach Choi
2023. 1. 17. 20:37
728x90
반응형
Solution
- Use Bitwise operator
class Solution {
public:
bool isPowerOfTwo(int n) {
if (n < 0)
{
return false;
}
else
{
return n && !(n & n - 1);
}
}
};
728x90
반응형