Given an integer, write a function to determine if it is a power of two.
public class Solution {
public boolean isPowerOfTwo1(int n) {
if (n < 0) return false;
for (int i = 0; i <32; i++) {
if (n == (1 << i))
return true;
}
return false;
}
public boolean isPowerOfTwo(int n) {
return n > 0 && (n & (n - 1)) == 0;
}
}