What mathematical operation does XOR perform?
Step 1 : Find “min” and “max” value in the given array. It will take O(n). Step 2 : Find XOR of all integers from range “min” to “max” ( inclusive ). Step 3 : Find XOR of all elements of the given array.
XOR is a bitwise operator, and it stands for "exclusive or." It performs logical operation. If input bits are the same, then the output will be false(0) else true(1).
XOR on the same argument: x ^ x = 0 If the two arguments are the same, the result is always 0 .
Find the Duplicate Number - LeetCode. Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive. There is only one repeated number in nums , return this repeated number. You must solve the problem without modifying the array nums and uses only constant extra space.
XOR is a binary operation, it stands for "exclusive or", that is to say the resulting bit evaluates to one if only exactly one of the bits is set.
This is its function table:
a | b | a ^ b --|---|------ 0 | 0 | 0 0 | 1 | 1 1 | 0 | 1 1 | 1 | 0
This operation is performed between every two corresponding bits of a number.
Example: 7 ^ 10
In binary: 0111 ^ 1010
0111 ^ 1010 ====== 1101 = 13
Properties: The operation is commutative, associative and self-inverse.
It is also the same as addition modulo 2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With