JAVA: Easy for understanding


  • 0
    A
    public int findComplement(int num) {
          String s = Integer.toBinaryString(num);
          s = s.replaceAll("0", "x").replaceAll("1", "0").replaceAll("x", "1");
          return Integer.parseInt(s, 2);
      }

Log in to reply
 

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