Javascript using regex match


  • 1
    G

    /**

    • @param {number} x
    • @param {number} y
    • @return {number}
      */
      var hammingDistance = function(x, y) {
      var ct=parseInt(x^y,10).toString(2).match(/1/g);
      return (ct)? ct.length:0;
      };

Log in to reply
 

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