O(1) Check Power of 2) : bad operand types for binary Operator ‘& ‘”.
First paste the code:
copy code
public class Solution {
/**
* @param n: An integer
* @return: True or false
*/
public boolean checkPowerOf2(int n) {
// write your code here
if(n<=0)
return false;
return (n&(n-1)==0)?true:false;
}
}
Copy the code
Error:
initially suspected an operator problem, but also ruled it out. I always think there is something wrong with the “true” and “false”, but I can’t find it. It turns out that it is really a priority problem and may be affected by the assignment (=) operator, as & “Is higher in priority than” == “, in fact the opposite is true. The identity operator has a higher priority than the bit operator, resulting in “&”; The left hand side is an int, and the right hand side is a Boolean.
so just put “return (n& (n-1)==0)?True, false;” Instead of “return ((n& (n-1))==0)?True, false;” It’ll be ok.
Read More:
- /usr/include/boost/type_traits/detail/has_binary_operator.hp:50: Parse error at “BOOST_JOIN”
- PySpark ERROR Shell: Failed to locate the winutils binary in the hadoop binary path
- Eclipse .java File Syntax error, parameterized types are only available if source level is 1.5 or
- Unsupported operation types unsupported operation data types
- [C + +] C + + overload operator = must be a nonstatic member function?
- C++ —Return multiple values of different types
- Group by operator of hive execution plan
- error C2679: binary ‘<<' : no operator found which takes a right-hand operand of type 'std::string'
- HALCON error #2036: could not find license file in operator set_ Part solution
- Typeerror: UFUNC ‘isn’t supported for the input types
- Python — magic identify file types
- error C2784: ‘bool std::operator <(const std::_Tre
- After upgrading php7, PHP program prompts an error: operator not supported for strings in causes and Solutions
- Analysis of compilation errors of “error conflicting types for function”
- Matlab prompts undefined operator ‘*’ for input arguments of type ‘cell’
- Cannot find module ‘internal / util / types’ appears during gulp build
- Error c2371: ‘xxx’: redefinition; different basic types solutions
- Square root of X (implementation of binary search)
- Binary tree traversal (preorder, middle order, postorder, hierarchy traversal, depth first, breadth first)
- NPM error ‘cannot find module’ internal / util / types’ solution;