I was solving this problem. I have a function go, which returns a boolean true or false. When I replace "|" with "||", I get AC, otherwise I get TLE on test 6. I get AC with "||" and "or", but TLE with "|". Can anyone tell me the difference between the three?

For booleans there is priority difference: http://en.cppreference.com/w/cpp/language/operator_precedence

Can you show your code? Possibly you use '|' and '&&' combination.

AC Code

TLE Code

Look in the last line of go function.

| is bitwise operator.

|| and "or" are logical operator.

As tyamgin said it could happen because of precedence.

"The & and | operators have lower precedence than comparison operators. That means that x & 3 == 1 is interpreted as x & (3 == 1), which is probably not what you want." Source

Thanks!

First of all,

`||`

and`or`

are identical, but there is a big difference between`|`

and`||`

.`||`

is a boolean operator.`a || b`

returns`true`

or`false`

. If`a`

is non-zero, then the value of`b`

is not checked (since the answer is guaranteed to be`true`

).`|`

is bitwise-or.`a | b`

returns a number (which can then be cast to a boolean if you need to). This evaluates both`a`

and`b`

, and then computes the bitwise or of them.The most likely reason that

`||`

is not getting TLE is because it is not evaluating the second operand. This is especially true if the second operand is a complex function that has to be evaluated.