Skip to content

Commit de3fdc9

Browse files
authored
Update Power of Four.java
1 parent 42b4851 commit de3fdc9

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

Easy/Power of Four.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
11
class Solution {
2-
public boolean isPowerOfFour(int n) {
3-
long left = 0;
4-
long right = n / 2 + 1;
5-
while (left <= right) {
6-
long mid = (left + right) / 2;
7-
long pow = (long) (Math.pow(4, mid));
8-
if (pow == ((long) n)) {
9-
return true;
10-
}
11-
if (pow > ((long) n)) {
12-
right = mid - 1;
13-
} else {
14-
left = mid + 1;
15-
}
2+
public boolean isPowerOfFour(int n) {
3+
return n > 0 && Math.log(n) / Math.log(2) % 2 == 0;
164
}
17-
return false;
18-
}
195
}

0 commit comments

Comments
 (0)