顿搜
飞过闲红千叶,夕岸在哪
类目归类
Implement pow(x, n).
Input 16
Output: True
public boolean isPowerOfTwo(int n) {
long num = n;
if (n == 0) {
return false;
}
return (num & (num - 1)) == 0;
}public class LeetCode0231 {
public boolean isPowerOfTwo(int n) {
long num = n;
if (n == 0) {
return false;
}
return (num & (num - 1)) == 0;
}
public static void main(String[] args) {
LeetCode0231 leetcode = new LeetCode0231();
System.out.println(leetcode.isPowerOfTwo(256));
}
}