Simple JavaScript Solution


  • 0
    /**
     * @param {number} num
     * @return {boolean}
     */
    var checkPerfectNumber = function(num) {
      if (num === 1) return false;
      let sum = 1;
      for(let i = 2; i <= Math.floor(Math.sqrt(num)); ++i) {
        if ( num % i === 0) {
          sum  += (num/i) + i; 
        }
      }
      if (sum === num) {
        return true;
      } else {
        return false;
      }
    };

Log in to reply
 

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