wild_card_entry

 avatar
bruteCoder
java
7 months ago
833 B
1
Indexable
Never

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();
    }
}


Leave a Comment