Skip to content

Commit ff278e4

Browse files
authored
Added CPP code for LeetCode question of Power of Four (#365)
1 parent b66f463 commit ff278e4

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

CPP/PowerOfFour.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class Solution {
2+
public:
3+
double value4(double d)
4+
{
5+
return (log2(d))/2;
6+
}
7+
bool is_integer(float k)
8+
{
9+
return std::floor(k) == k;
10+
}
11+
bool isPowerOfFour(int n) {
12+
if(n<=0){
13+
return false;
14+
}
15+
if(n==1){
16+
return true;
17+
}
18+
if(n%4!=0){
19+
return false;
20+
}
21+
else{
22+
if(is_integer(value4(n))){
23+
return true;
24+
}
25+
else{
26+
return false;
27+
}
28+
}
29+
}
30+
};

0 commit comments

Comments
 (0)