def is_power_of_two(n):
return n>0 and (n&(n-1))==0
public boolean isPowerOfTwo(int n){
return n>0&&(n&(n-1))==0;
}
Nearly identical. and vs &&.
def is_power_of_two(n):
return n>0 and (n&(n-1))==0
public boolean isPowerOfTwo(int n){
return n>0&&(n&(n-1))==0;
}
1. Positive and one bit set