![]() |
VOOZH | about |
Given two integers A & B. Task is to check if A and B are same or not without using comparison operators.
Examples:
Input : A = 5 , B = 6
Output : 0Input : A = 5 , B = 5
Output : 1Note : 1 = "YES" and 0 = "NO"
The idea is pretty simple we do Xor of both elements ( A, B ). if Xor is zero then two numbers are equal else not.
Below is the implementation of the above idea :
0
Time Complexity: O(1)
Auxiliary Space: O(1)
2nd Method:
Another Approach is using "-" (Minus/Subtraction Operator). If the Result of Subtraction between the two Numbers is "Zero", then they are equal (we return '1'), else they are not equal (we return '0').
0
Time Complexity: O(1)
Auxiliary Space: O(1)