Input: 31, 14
Output: 2
class digit_prob
{
public static int bitSwapRequired(int a, int b)
{
int count = 0;
for (int c = a ^ b; c != 0; c = c >> 1) {
count += c & 1;
}
return count;
}
public static void main(String a[])
{
System.out.println(bitSwapRequired(10,9));
}
}
TC O(n)
Sc O(1)
Run Here https://ideone.com/VaBTS
No comments :
Post a Comment