TLE for javaScript, same solution accepted for C++


  • 0
    L

    Here is my solution in javaScript. Get Time Limit Exceeded.
    But my C++ solution with the same algorithm was accepted.

    var hammingWeight = function(n) {
         
         var numOfZero = 0;
            while(n){
                
                numOfZero += n%2;
                n>>=1;
            }
         return numOfZero;
    };

  • 0
    L

    accepted using the function parseInt().


Log in to reply
 

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