Math & Bit Manipulation, Power of X
public class Solution {
public boolean isPowerOfTwo(int n) {
return (n > 0) && (((n - 1) & n) == 0);
}
} public static boolean isPowerOfThree(int n) {
if (n <= 0)
return false;
double r = Math.log10(n) / Math.log10(3);
if (r % 1 == 0)
return true;
else
return false;
}这么干和作弊差不多=。= 对喜欢问这种问题的公司致以深深的鄙视。
Last updated