Problem 231: Power of Two
思路

public class Solution {
public boolean isPowerOfTwo(int n) {
if (n <= 0) {
return false;
}
return ((n - 1) & n) == 0;
}
}易错点
return ((n - 1) & n) == 0;
Last updated

public class Solution {
public boolean isPowerOfTwo(int n) {
if (n <= 0) {
return false;
}
return ((n - 1) & n) == 0;
}
}return ((n - 1) & n) == 0;Last updated