wild_card_entry
bruteCoder
java
2 years ago
833 B
7
Indexable
class Solution
{
//Function to find the first position with different bits.
public static int posOfRightMostDiffBit(int m, int n)
{
// Your code here
if(m==n) return -1;
String one = getBinary(m);
String two = getBinary(n);
// System.out.println(one + " " + two);
int i = 0;
while(i < one.length() && i < two.length())
{
if(one.charAt(i) != two.charAt(i)) return i+1;
i+=1;
}
return i+1;
}
public static String getBinary(int m)
{
StringBuilder sb = new StringBuilder();
while(m > 0){
int get = m%2;
sb.append(get);
m /= 2;
}
return sb.toString();
}
}
Editor is loading...
Leave a Comment