my javascript solution


  • 0
    Z
    /**
     * @param {number} n
     * @return {boolean}
     */
    function isHappy(n) {
        while (n > 6) {
            let next = 0;
            while (n) {
                next += (n % 10) * (n % 10);
                n = Math.trunc(n / 10);
            }
            n = next;
        }
        return n === 1;
    }
    

Log in to reply
 

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