JavaScript Solution


  • 0
    O

    /**

    • @param {number} n

    • @return {boolean}
      */
      var isHappy = function(n) {
      if(n == 1 || n == 7){return true;}
      if(n>1 && n < 10){return false;}

      var str = n.toString();
      var arr = str.split('');
      var sum = 0;
      arr.map(function(a){sum+=Math.pow(a, 2);})
      return arguments.callee(sum);
      };


Log in to reply
 

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