3 lines of JAVA solution


  • 0
    C
    public int findComplement(int num) {
            String resS = "";
            for(char c : Integer.toBinaryString(num).toCharArray()) {resS += Math.abs(c-'1');}
            return Integer.parseInt(resS,2);
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.