HashMap & Set

Happy Number

easy
A happy number is a number defined by the following process: - Starting with any positive integer, replace the number by the sum of the squares of its digits. - Repeat until the number equals 1 (happy), or it loops endlessly in a cycle (unhappy). Return `true` if `n` is a happy number, else `false`. Example: `isHappy(19)` → `true` because 1²+9²=82 → 68 → 100 → 1.
Hint steps(0/3 revealed)
  1. 1

    Complete previous step or reveal to unlock this hint.

  2. 2

    Complete previous step or reveal to unlock this hint.

  3. 3

    Complete previous step or reveal to unlock this hint.