forked from yubinbai/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
39 lines (31 loc) · 680 Bytes
/
main.cpp
File metadata and controls
39 lines (31 loc) · 680 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
class Solution {
public:
bool isPowerOfFour(int num) {
// 0b01010101010101010101010101010101
int filter = 1431655765;
return num > 0 &&
(num & (num - 1)) == 0 &&
(num & filter) == num;
}
};
int main() {
Solution sol;
cout << sol.isPowerOfFour(16) << endl;
cout << sol.isPowerOfFour(5) << endl;
cout << sol.isPowerOfFour(0) << endl;
cout << sol.isPowerOfFour(1) << endl;
return 0;
}