JavaScript Solution using & and !


  • 0
    A

    /**

    • @param {number} num
    • @return {number}
      */
      var findComplement = function(num) {
      var pow = output = 1;
      if(num){
      output = 0;
      while(num){
      output+= (!(num&1))pow;
      pow
      =2;
      num = num >>>1;
      }
      }
      return output;
      };

Log in to reply
 

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