题目描述
Given two non-negative integers a and b. The problem is to check whether the two numbers differ at one-bit position only or not. If yes then the answer is 1, otherwise 0.
Example 1:
Input: a = 13, b = 9
Output: 1
Explanation: (13){10} = (1101)
(9){10} = (1001)
Both the numbers differ at one bit
position only, i.e, differ at the
3rd bit from the right.
Example 2:
Input: a = 15, b = 8
Output: 0
Explanation: (15){10} = (1111)
(8){10} = (1000)
Both the numbers differ at 3 bit
positions.
Your Task:
You don't need to read input or print anything. Your task is to complete the function DifferOne() which takes a, b as inputs and returns the answer.
Expected Time Complexity: O(max(log a, log b))
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ a, b ≤ 10^{9}
输入格式
见题面
输出格式
见题面