1-Line Functional JavaScript Solution


  • 0
    F
    function findComplement(num) {
      return [1, 2, 4, 8, 16].reduce((val, shift) => val | (val >> shift), num) - num
    }
    

Log in to reply
 

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