#231. Power of Two
Given an integer, write a function to determine if it is a power of two.
the same as [326. Power of Three](./Solution/326. Power of Three.md)
Java Solution
public class Solution {
public boolean isPowerOfTwo(int n) {
return (n>0 && 1073741824%n==0);
}
}
对数解决 为什么用log10
Java Solution
public class Solution {
public boolean isPowerOfTwo(int n) {
if(n<0)return false;
double rest = Math.log10(n)/Math.log10(2);
if(rest%1==0) return true;
return false;
}
}