Ai
1 Star 2 Fork 5

LilithSangreal/LeetCode-Solutions

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
power-of-four.cpp 418 Bytes
Copy Edit Raw Blame History
kamyu authored 2016-04-18 11:09 +08:00 . Update power-of-four.cpp
// Time: O(1)
// Space: O(1)
class Solution {
public:
bool isPowerOfFour(int num) {
return num > 0 && (num & (num - 1)) == 0 &&
((num & 0b01010101010101010101010101010101) == num);
}
};
// Time: O(1)
// Space: O(1)
class Solution2 {
public:
bool isPowerOfFour(int num) {
while (num && !(num & 0b11)) {
num >>= 2;
}
return (num == 1);
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

Search